:root {
  --bg: #f6efe9;
  --surface: #fffdfb;
  --surface-2: #f2e8e2;
  --ink: #2c2c2c;
  --muted: #6f6762;
  --line: #e4d6cc;
  --gold: #a86f50;
  --gold-soft: #d9b59a;
  --gold-ink: #7a4d36;
  --ok: #2f7a4f;
  --ok-bg: #e3f1e8;
  --warn: #9a5b00;
  --warn-bg: #fbeed6;
  --bad: #b23a2e;
  --bad-bg: #f8e1de;
  --cash: #2f7a4f;
  --card: #2f5d8a;
  --radius: 14px;
  --shadow: 0 1px 2px #2c2c2c14, 0 6px 18px #2c2c2c0f;
  --font: "Avenir Next", Avenir, "Segoe UI", Helvetica, Arial, sans-serif;
  --display: Didot, "Bodoni 72", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1b1a; --surface: #272423; --surface-2: #322e2c; --ink: #f3ece7; --muted: #b5aaa3; --line: #403a37;
    --gold: #d9b59a; --gold-soft: #8d6048; --gold-ink: #ecd2bf;
    --ok: #7fcf9c; --ok-bg: #1f3428; --warn: #f0c060; --warn-bg: #3a2f17; --bad: #f08a7e; --bad-bg: #3d2220;
    --cash: #7fcf9c; --card: #8fb8e6; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #1d1b1a; --surface: #272423; --surface-2: #322e2c; --ink: #f3ece7; --muted: #b5aaa3; --line: #403a37;
    --gold: #d9b59a; --gold-soft: #8d6048; --gold-ink: #ecd2bf;
    --ok: #7fcf9c; --ok-bg: #1f3428; --warn: #f0c060; --warn-bg: #3a2f17; --bad: #f08a7e; --bad-bg: #3d2220;
    --cash: #7fcf9c; --card: #8fb8e6; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); min-height: 100vh; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-family: var(--display); font-weight: 400; font-size: 1.7rem; letter-spacing: .01em; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 700; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- structure ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.brand span { font-family: var(--display); font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.who b { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 96px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 9px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: .92rem; }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 4px 0 14px; }
.head .grow { flex: 1; min-width: 12rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel > h2 { margin-bottom: 10px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid2 > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.open { background: var(--ok-bg); color: var(--ok); }
.badge.closed { background: var(--surface-2); color: var(--muted); }
.badge.planned { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---------- boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); font-weight: 650; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--gold-soft); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .88rem; border-radius: 9px; }
.btn.link { border: 0; background: none; color: var(--gold-ink); text-decoration: underline; padding: 4px; min-height: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- gros compteurs ---------- */
.counters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.counter { position: relative; border-radius: 18px; border: 2px solid var(--line); background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.counter.cash { border-color: color-mix(in srgb, var(--cash) 45%, var(--line)); }
.counter.card { border-color: color-mix(in srgb, var(--card) 45%, var(--line)); }
.counter .plus { width: 100%; min-height: 150px; border: 0; background: transparent; display: grid; align-content: center; justify-items: center; gap: 2px; padding: 14px 8px 46px; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.counter .plus:active { background: var(--surface-2); }
.counter .label { font-weight: 800; font-size: 1.05rem; }
.counter .sub { font-size: .82rem; color: var(--muted); }
.counter .n { font-size: 2.6rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.counter.cash .n { color: var(--cash); }
.counter.card .n { color: var(--card); }
.counter .minus { position: absolute; left: 8px; bottom: 8px; min-height: 32px; min-width: 44px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 700; cursor: pointer; }
.counter .pending { position: absolute; right: 10px; bottom: 12px; font-size: .75rem; color: var(--warn); font-weight: 700; }
.counter.flash { animation: flash .35s ease; }
@keyframes flash { from { background: var(--gold-soft); } to { background: var(--surface); } }
.counter.wide { grid-column: 1 / -1; }
.counter.wide .plus { min-height: 190px; }
.counter.wide .n { font-size: 3.4rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi small { display: block; font-size: .78rem; }
.kpi b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.kpi.ok b { color: var(--ok); } .kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }

/* ---------- formulaires ---------- */
label.f { display: grid; gap: 4px; font-size: .88rem; font-weight: 600; }
label.f > span small { font-weight: 400; }
input, select, textarea { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
textarea { min-height: 70px; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--gold); }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); align-items: end; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checks label { display: flex; align-items: center; gap: 6px; font-size: .92rem; }

/* ---------- tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
td.r, th.r { text-align: right; }
td input { min-height: 40px; padding: 6px 8px; max-width: 7rem; text-align: right; }
tfoot td { font-weight: 800; border-bottom: 0; }
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.lines li:last-child { border-bottom: 0; }
.lines li.total { font-weight: 800; border-top: 1px solid var(--ink); border-bottom: 0; }

/* ---------- état ---------- */
.notice { padding: 10px 14px; border-radius: 11px; background: var(--surface-2); margin-bottom: 12px; font-size: .92rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.gap-ok { color: var(--ok); font-weight: 700; } .gap-bad { color: var(--bad); font-weight: 700; } .gap-warn { color: var(--warn); font-weight: 700; }
.offline { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 10px 16px; text-align: center; background: var(--warn); color: #fff; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 11px; background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 10px 30px #0004; }
.toast.err { background: var(--bad); color: #fff; }

.event-list { display: grid; gap: 10px; }
.event-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.event-item:hover { border-color: var(--gold-soft); }
.event-item .grow { flex: 1; min-width: 0; }
.event-item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 26px 22px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login img { width: 100%; max-width: 300px; justify-self: center; }

@media (max-width: 420px) {
  .counter .n { font-size: 2.2rem; }
  .counter .plus { min-height: 132px; }
  .who .role { display: none; }
}
