:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --line: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --p0: #2a78d6;
  --p1: #eb6834;
  --bar: #2a78d6;
  --warn-bg: #fff6e0;
  --warn-line: #eda100;
  --danger: #c4302b;
  --ok-bg: #e7f6ee;
  --err-bg: #fdecec;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --line: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --p0: #3987e5;
    --p1: #d95926;
    --bar: #3987e5;
    --warn-bg: #2b2210;
    --warn-line: #c98500;
    --danger: #e66767;
    --ok-bg: #12291d;
    --err-bg: #301617;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
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;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: .4em 0 .6em; }
h2 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
.card h2 { margin-top: 0; }
.wrap { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* En-tête + barre d'onglets */
.top {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 640px; margin: 0 auto; padding: 12px 16px 0;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.who { color: var(--muted); font-size: .9rem; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 128px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 9px; font-size: .72rem; color: var(--muted); text-decoration: none;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current] { color: var(--accent); font-weight: 600; }

/* Cartes, boutons */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.eyebrow { margin: 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 1.3rem; font-weight: 650; margin: .2em 0 .3em; }
.balance .btn { margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .9rem; }
.btn.icon { width: 44px; padding: 0; font-size: 1.5rem; }
.btn.block { display: flex; width: 100%; }
.add { margin: 16px 0; min-height: 52px; font-size: 1.05rem; }

.flash { padding: 10px 14px; border-radius: 10px; margin: 10px 0; background: var(--ok-bg); }
.flash.err { background: var(--err-bg); }

/* Navigation de mois */
.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthnav h1 { margin: .4em 0; text-align: center; }

/* Listes */
.row-head { display: flex; justify-content: space-between; align-items: baseline; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; gap: 12px; align-items: center; padding: 12px 14px; color: inherit; text-decoration: none; }
.list a:hover { background: var(--surface-2); }
.list .when { color: var(--muted); font-size: .85rem; width: 38px; flex: none; font-variant-numeric: tabular-nums; }
.list .what { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list .what strong { font-weight: 550; overflow-wrap: anywhere; }
.list .what small { color: var(--muted); }
.list .amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; display: flex; flex-direction: column; }
.list .amt small { font-weight: 400; color: var(--muted); }
.projected { opacity: .55; }
.tag { display: inline-block; font-size: .7rem; font-weight: 500; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); vertical-align: 2px; }
.tag.warn { background: var(--warn-bg); color: var(--text); border: 1px solid var(--warn-line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot.p0 { background: var(--p0); }
.dot.p1 { background: var(--p1); }

.check-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.check-row .grow { flex: 1; min-width: 0; }
.check-row input[type=text] { width: 104px; flex: none; }

/* Tableaux */
.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.tbl th:first-child { text-align: left; font-weight: 550; white-space: nowrap; }
.tbl td { white-space: nowrap; }
.card .tbl { font-size: .92rem; }
.tbl thead th { font-weight: 500; color: var(--muted); font-size: .85rem; }
.tbl tr:last-child > * { border-bottom: 0; }

/* Formulaires */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .form fieldset { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: .92rem; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { padding: 0; margin-bottom: 4px; font-weight: 550; font-size: .92rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.amount { font-size: 1.5rem; font-weight: 600; }
.form label.inline, label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.inline input { width: 20px; height: 20px; flex: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg { display: flex; gap: 6px; }
.seg-wrap { flex-wrap: wrap; }
.seg label { flex: 1; min-width: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 44px; padding: 4px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-weight: 500; cursor: pointer;
}
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.split-custom { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.split-custom label { flex-direction: row !important; align-items: center; gap: 8px; }
.split-custom input { width: 84px; }

.danger-zone { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.inline-form input[type=text] { flex: 1; }
details summary { cursor: pointer; color: var(--accent); margin: 10px 0; }

.login { max-width: 380px; margin: 12vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.login h1 { text-align: center; }
.login label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; }

/* Historique */
.day { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.event { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0; }
.event p { margin: 0 0 4px; overflow-wrap: anywhere; }
.event .meta { font-size: .82rem; color: var(--muted); }
.event.undone > p:not(.meta) { text-decoration: line-through; color: var(--muted); }
.event .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.event .actions:empty { display: none; }
.act-delete { color: var(--danger); }
.pager { display: flex; justify-content: space-between; margin-top: 16px; }

/* Budget */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tiles .card { margin: 4px 0; padding: 12px; }
.tiles .big { font-size: 1.05rem; }
@media (max-width: 420px) { .tiles { grid-template-columns: 1fr 1fr; } .tiles .card:first-child { grid-column: span 2; } }

.cols { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; text-decoration: none; }
.col .bar { width: 100%; max-width: 24px; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 1px; }
.col.future .bar { background: repeating-linear-gradient(135deg, var(--bar) 0 3px, transparent 3px 6px); opacity: .55; }
.col .lbl { position: absolute; bottom: -22px; font-size: .75rem; color: var(--muted); }
.col.now .lbl { color: var(--text); font-weight: 700; }
.col:hover .bar, .col:focus-visible .bar { filter: brightness(1.15); }
.col:hover::after, .col:focus-visible::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; background: var(--text); color: var(--bg); font-size: .8rem; padding: 4px 8px; border-radius: 6px; z-index: 2;
}
.col:first-child:hover::after, .col:nth-child(2):hover::after { left: 0; transform: none; }
.col:last-child:hover::after, .col:nth-last-child(2):hover::after { left: auto; right: 0; transform: none; }
.legend { margin-top: 30px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--bar); }
.key.future { background: repeating-linear-gradient(135deg, var(--bar) 0 3px, transparent 3px 6px); opacity: .55; margin-left: 10px; }

.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: minmax(0, 9em) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.hbars .name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .track { height: 12px; }
.hbars .bar { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; font-weight: 550; text-align: right; display: flex; flex-direction: column; font-size: .9rem; }
.hbars .val small { color: var(--muted); font-weight: 400; }
