:root {
  --bg: #f4f5f2; --card: #ffffff; --ink: #1c2321; --muted: #6b7471; --line: #e3e6e2;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e1f2ef;
  --warn: #b45309; --warn-soft: #fef3c7; --danger: #b91c1c; --ok: #15803d;
  --radius: 14px; --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615; --card: #1a2120; --ink: #e8ecea; --muted: #94a09c; --line: #2a3331;
    --brand: #2dd4bf; --brand-ink: #062a26; --brand-soft: #123532;
    --warn: #fbbf24; --warn-soft: #3a2e10; --danger: #f87171; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: .5rem 0 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }

input, button { font: inherit; color: inherit; }
input {
  width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); min-height: 46px;
}
input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.lbl { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: .8rem 0 .3rem; text-transform: uppercase; letter-spacing: .03em; }

.btn {
  border: 1px solid var(--line); background: var(--card); padding: .65rem 1rem; border-radius: 10px;
  min-height: 46px; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { width: 100%; margin-top: 1rem; min-height: 54px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: .35rem .75rem; font-size: .9rem; }
.btn.danger { color: var(--danger); }
.btn:active { transform: scale(.98); }

/* Écrans */
.screen { min-height: 100dvh; }
.login-box { max-width: 340px; margin: 0 auto; padding: 3rem 1rem; text-align: center; }
.login-logo { width: 140px; height: 140px; border-radius: 50%; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 1.25rem 0; min-height: 16px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button { min-height: 64px; font-size: 1.5rem; border: 1px solid var(--line); border-radius: 16px; background: var(--card); cursor: pointer; }
.keypad button.ghost { background: transparent; border-color: transparent; font-size: 1rem; }
.error { color: var(--danger); min-height: 1.4em; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.badge { font-size: .7rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); padding: .15rem .5rem; border-radius: 99px; margin-left: .3rem; vertical-align: middle; text-transform: uppercase; }
.pill { border: 0; border-radius: 99px; padding: .35rem .75rem; font-size: .8rem; font-weight: 600; cursor: pointer; background: var(--brand-soft); color: var(--brand); }
.pill.offline { background: var(--warn-soft); color: var(--warn); }

main { max-width: 720px; margin: 0 auto; padding: 1rem 1rem calc(var(--tabs-h) + 1.5rem + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; margin-top: .5rem; }
.row.center { justify-content: center; align-items: center; flex-wrap: nowrap; }
.row.center input { max-width: 200px; }
.col { flex: 1 1 140px; min-width: 0; }
.hint { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; min-height: 1.2em; }
.hint.warn { color: var(--warn); }

/* Vente */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; max-height: 220px; overflow-y: auto; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: .5rem .7rem; cursor: pointer; text-align: left; min-height: 44px; }
.chip small { display: block; color: var(--muted); font-size: .75rem; }
.chip.free { border-style: dashed; }
.selected { margin-top: .6rem; padding: .7rem .8rem; border-radius: 10px; background: var(--brand-soft); display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.selected button { border: 0; background: transparent; color: var(--brand); font-weight: 700; cursor: pointer; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-top: 1rem; }
.seg button { flex: 1; border: 0; background: transparent; padding: .55rem; border-radius: 9px; font-weight: 600; cursor: pointer; min-height: 42px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.seg.small { margin: 0 0 .75rem; }
.seg.small button { min-height: 34px; padding: .3rem; font-size: .9rem; }
.stepper { display: flex; gap: .4rem; }
.stepper button { width: 46px; flex: none; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; font-size: 1.3rem; cursor: pointer; }
.stepper input { text-align: center; }

.list { list-style: none; margin: .5rem 0 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { min-width: 0; flex: 1; }
.list .main b { display: block; overflow: hidden; text-overflow: ellipsis; }
.list .main small { color: var(--muted); }
.list .amt { font-weight: 700; white-space: nowrap; text-align: right; }
.list .acts { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.list .empty { color: var(--muted); justify-content: center; }
.tag { font-size: .7rem; padding: .1rem .45rem; border-radius: 99px; font-weight: 700; background: var(--bg); border: 1px solid var(--line); }
.tag.wait { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.ok { color: var(--ok); }
.tag.gros { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.strike { text-decoration: line-through; opacity: .55; }

/* Crédits */
.citem { display: grid; grid-template-columns: 1fr 70px 110px 36px; gap: .4rem; margin-bottom: .4rem; }
.citem button { border: 0; background: transparent; color: var(--danger); font-size: 1.2rem; cursor: pointer; }
.total-line { margin: 1rem 0; font-size: 1.05rem; }
.credit-detail { font-size: .85rem; color: var(--muted); margin-top: .3rem; }

/* Rapport */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-top: 1rem; }
.kpi { background: var(--bg); border-radius: 12px; padding: .7rem; }
.kpi span { display: block; font-size: .75rem; color: var(--muted); }
.kpi strong { font-size: 1.05rem; }
.kpi.main { grid-column: 1 / -1; background: var(--brand); color: var(--brand-ink); }
.kpi.main span { color: inherit; opacity: .85; }
.kpi.main strong { font-size: 1.8rem; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .5rem .3rem; border-top: 1px solid var(--line); text-align: left; }
.table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; border-top: 0; }
.table .r { text-align: right; }

/* Onglets */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; border: 0; background: transparent; height: var(--tabs-h); font-size: .72rem; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button .ic { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--brand); font-weight: 700; }
.tabs button.on .ic { filter: none; opacity: 1; }
body:not(.is-admin) .admin-only { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 1rem + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; max-width: calc(100% - 2rem); z-index: 10; font-weight: 600;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 420px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .citem { grid-template-columns: 1fr 56px 90px 30px; }
}
.login-box { text-align: center; }
.login-box .lbl { text-align: left; }
select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .45rem .6rem; min-height: 40px; }
.pill { white-space: nowrap; }
.brand { display: flex; align-items: center; gap: .5rem; }
.brand-logo { width: 32px; height: 32px; border-radius: 50%; flex: none; }
