:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #17211d; --muted: #5d6b65; --line: #e1e7e4;
  --primary: #1f6f5c; --primary-ink: #ffffff; --primary-soft: #e3f1ed;
  --pos: #12794f; --neg: #b42318; --warn: #8a5a00; --warn-bg: #fff4d6; --err-bg: #fde8e6; --ok-bg: #e3f6ec;
  --shadow: 0 1px 2px rgba(16,24,20,.06), 0 4px 14px rgba(16,24,20,.05);
  --radius: 14px;
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1613; --card: #17211d; --ink: #e8efec; --muted: #9aaba3; --line: #2a3832;
    --primary: #3fae93; --primary-ink: #06130f; --primary-soft: #1b3029;
    --pos: #4cc38f; --neg: #ff8a7a; --warn: #f2c14e; --warn-bg: #33290d; --err-bg: #3b1c18; --ok-bg: #123325;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
body.bare { padding: 24px 16px; min-height: 100vh; display: grid; place-items: center; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .4rem; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .3rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: .3rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.hide-mobile { display: none; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .zero { color: var(--muted); }
.faded { opacity: .5; }

/* ---------- barre du haut ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--primary); color: var(--primary-ink); }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: rgba(255,255,255,.2); font-weight: 800; }
.logo.big { width: 64px; height: 64px; font-size: 2rem; background: var(--primary); color: var(--primary-ink); margin: 0 auto 12px; border-radius: 18px; }
.desktop-nav { display: none; gap: 4px; margin-left: 12px; flex: 1; }
.desktop-nav a { color: inherit; padding: 6px 12px; border-radius: 8px; opacity: .9; }
.desktop-nav a:hover { background: rgba(255,255,255,.15); text-decoration: none; }
.desktop-nav a.active { background: rgba(255,255,255,.25); font-weight: 600; opacity: 1; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: rgba(255,255,255,.15); }
.hamb, .hamb::before, .hamb::after { display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; content: ""; position: relative; }
.hamb::before { position: absolute; top: -6px; } .hamb::after { position: absolute; top: 6px; }
.menu-panel { position: absolute; right: 0; top: 46px; min-width: 230px; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: 8px; display: grid; }
.menu-panel a, .menu-panel .linklike { padding: 10px 12px; border-radius: 8px; color: var(--ink); text-align: left; }
.menu-panel a:hover, .menu-panel .linklike:hover { background: var(--primary-soft); text-decoration: none; }
.menu-panel .who { padding: 6px 12px 8px; color: var(--muted); margin: 0; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

/* ---------- mise en page ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card.narrow, .narrow { max-width: 460px; width: 100%; }
.narrow-card { max-width: 620px; margin-left: auto; margin-right: auto; }
.card-head, .pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2, .pagehead h1 { margin: 0; }
.pagehead { margin-bottom: 10px; flex-wrap: wrap; }
.count { font-weight: 500; color: var(--muted); font-size: .85rem; background: var(--bg); padding: 1px 8px; border-radius: 99px; margin-left: 4px; }
.cards3 { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 14px; }
.stat { margin: 0; }
.label { margin: 0; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 2.1rem; font-weight: 750; margin: .1rem 0 .3rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bigish { font-size: 1.2rem; }
.hero { text-align: center; padding: 22px 16px; }

/* ---------- navigation de mois ---------- */
.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.monthtitle { text-align: center; flex: 1; }
.monthtitle h1 { margin: 0; text-transform: capitalize; }
.navbtn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 1.6rem; color: var(--ink); line-height: 1; box-shadow: var(--shadow); }
.navbtn:hover { text-decoration: none; background: var(--primary-soft); }
.navbtn.off { opacity: .35; }

/* ---------- boutons & formulaires ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { text-decoration: none; background: var(--primary-soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: .85rem; cursor: pointer; min-height: 34px; }
.chip.on { background: var(--ok-bg); border-color: var(--pos); color: var(--pos); }
.chip:hover { background: var(--primary-soft); }
label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .92rem; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
label.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: inherit; font-weight: 400; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="checkbox"] { display: inline-block; width: 20px; min-height: 0; height: 20px; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 2px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 700; }
.row2 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
.row3 { display: grid; gap: 0 12px; grid-template-columns: 1fr; align-items: end; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline input, .inline select { margin: 0; min-height: 38px; padding: 6px 10px; width: auto; max-width: 150px; }
.amtform input, .amtinput { width: 110px; text-align: right; }
.danger-zone { margin-top: 22px; padding-top: 14px; border-top: 1px dashed var(--line); }
small { display: block; margin-top: 2px; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); vertical-align: middle; }
.badge.okb { background: var(--ok-bg); color: var(--pos); }

/* ---------- messages ---------- */
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; background: var(--ok-bg); color: var(--pos); font-weight: 600; }
.flash.err { background: var(--err-bg); color: var(--neg); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.err-box { background: var(--err-bg); color: var(--neg); padding: 10px 14px; border-radius: 12px; margin-bottom: 14px; }
.err-box ul { margin: 0; padding-left: 18px; }
.ok-box { background: var(--ok-bg); color: var(--pos); padding: 10px 14px; border-radius: 12px; font-weight: 600; }

/* ---------- listes ---------- */
ul.plain, ul.txlist, ul.bars { list-style: none; margin: 0; padding: 0; }
ul.plain > li { padding: 10px 0; border-top: 1px solid var(--line); }
ul.plain > li:first-child { border-top: 0; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.txlist li { border-top: 1px solid var(--line); }
.txlist li:first-child { border-top: 0; }
.txrow { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; color: inherit; }
.txrow:hover { text-decoration: none; background: var(--primary-soft); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.txdate { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.txmain { display: flex; flex-direction: column; min-width: 0; }
.txcat { font-weight: 600; }
.txlabel { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txamt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars li { display: grid; grid-template-columns: minmax(90px, 1.2fr) 2fr auto; gap: 10px; align-items: center; padding: 6px 0; }
.barval { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
progress { width: 100%; height: 10px; border-radius: 99px; overflow: hidden; appearance: none; -webkit-appearance: none; border: 0; background: var(--bg); }
progress::-webkit-progress-bar { background: var(--bg); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }
progress.grey::-webkit-progress-value { background: var(--muted); } progress.grey::-moz-progress-bar { background: var(--muted); }
.more summary, .catitem summary { cursor: pointer; color: var(--primary); padding: 6px 0; }
.catitem summary { color: var(--ink); }
.catactions { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 0 10px; }

/* ---------- tableaux ---------- */
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.sum th { text-align: left; font-weight: 500; padding: 7px 0; } .sum td { text-align: right; font-weight: 600; padding: 7px 0; }
.sum tbody tr { border-top: 1px solid var(--line); }
.sum tfoot th, .sum tfoot td { border-top: 2px solid var(--ink); padding-top: 9px; font-weight: 800; font-size: 1.05rem; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table.lines th, table.lines td { padding: 6px 4px; text-align: left; } table.lines input { margin: 0; min-height: 40px; }
table.year { font-size: .85rem; min-width: 1100px; }
table.year th, table.year td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.year thead th { position: sticky; top: 0; background: var(--card); font-weight: 700; }
table.year .sticky { position: sticky; left: 0; background: var(--card); text-align: left; z-index: 2; min-width: 190px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
table.year .sechead th { background: var(--primary-soft); color: var(--primary); text-transform: uppercase; font-size: .75rem; letter-spacing: .05em; text-align: left; }
table.year .subtotal th, table.year .subtotal td { font-weight: 700; border-top: 1px solid var(--muted); }
table.year .soldrow th, table.year .soldrow td { font-weight: 800; border-top: 2px solid var(--ink); font-size: .92rem; }
table.year .totalcol { background: var(--bg); font-weight: 700; }
table.year td.cur, table.year th.cur { background: var(--primary-soft); }
.yearnav { display: flex; justify-content: space-between; }
.monthgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 12px; }

/* ---------- graphique ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .bar-pos { fill: var(--pos); } .chart .bar-neg { fill: var(--neg); } .chart .bar-cur { stroke: var(--ink); stroke-width: 2; }
.chart .axis-label { fill: var(--muted); font-size: 12px; }

/* ---------- barre du bas (mobile) ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); }
.tabbar a { display: grid; justify-items: center; gap: 2px; color: var(--muted); font-size: .72rem; font-weight: 600; padding: 6px 0; }
.tabbar a:hover { text-decoration: none; }
.tabbar a.active { color: var(--primary); }
.tabbar .ico { font-size: 1.3rem; line-height: 1; }
.tabbar .fab { width: 56px; height: 56px; margin: -22px auto 0; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-size: 2rem; font-weight: 400; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(0,0,0,.25); }

/* ---------- grands écrans ---------- */
@media (min-width: 720px) {
  .hide-mobile { display: inline-flex; }
  .cards3 { grid-template-columns: repeat(3, 1fr); }
  .row2 { grid-template-columns: 1fr 1fr; }
  .row3 { grid-template-columns: 2fr 1fr auto; }
  .monthgrid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .desktop-nav { display: flex; }
  .container { padding: 24px; }
}
@media print {
  .topbar, .tabbar, .btn, .navbtn { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Sélecteur de mois et pointage */
.monthpick { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 14px 0; }
.monthpick legend { font-weight: 600; padding: 0 6px; }
.monthpick .presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.monthchecks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 10px; }
.monthchecks label.check { margin: 0; }
@media (min-width: 640px) { .monthchecks { grid-template-columns: repeat(6, 1fr); } }
.todo { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.checkform { margin: 4px 0 0; }
