:root {
  --foret: #1E4633; --foret-2: #2B5E46; --sauge: #E9EFE8; --papier: #FFFFFF; --encre: #16201B;
  --gris: #5E6B64; --trait: #CDD8CF; --ambre: #B7790A; --ambre-bg: #FBF1DC; --rouge: #B3261E;
  --rouge-bg: #FBE7E5; --vert: #2F7D4E; --vert-bg: #E1F1E6; --focus: #3E8EDE;
  --radius-s: 6px; --radius-m: 10px;
  --font: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-num: "Barlow Semi Condensed", "Barlow", "Segoe UI", system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --foret: #173828; --foret-2: #6FB38D; --sauge: #111A15; --papier: #1A2520; --encre: #E4ECE6;
    --gris: #9DAAA2; --trait: #2E3D35; --ambre: #E4AA3E; --ambre-bg: #3A2E13; --rouge: #F08C84;
    --rouge-bg: #3B1C1A; --vert: #7CCB98; --vert-bg: #173323;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--sauge); color: var(--encre); font: 16px/1.45 var(--font); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--gris); }
.pad { padding: 1.5rem; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* Barre du haut */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 1rem;
  background: var(--foret); color: #F2F6F3; padding: .6rem 1rem; }
.brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
#nav { display: flex; gap: .25rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
#nav a { color: #CFE0D5; text-decoration: none; padding: .45rem .75rem; border-radius: var(--radius-s); white-space: nowrap; font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
#nav a[aria-current="page"] { background: #F2F6F3; color: var(--foret); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #nav a[aria-current="page"] { background: var(--foret-2); color: #0E1A13; } }
.who { font-size: .85rem; color: #CFE0D5; white-space: nowrap; display: flex; gap: .8rem; align-items: center; }
.who a { color: #F2F6F3; }
@media (max-width: 720px) { .who .mail { display: none; } .brand { flex: 1; } .topbar { flex-wrap: wrap; } #nav { order: 3; flex-basis: 100%; } }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 7rem; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.section { background: var(--papier); border: 1px solid var(--trait); border-radius: var(--radius-m); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }

label.f { display: block; font-size: .9rem; color: var(--gris); margin-bottom: .3rem; }
.input, select, textarea { width: 100%; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--radius-s); padding: .6rem .7rem; }
.input:focus, select:focus, textarea:focus { border-color: var(--foret-2); }
.money { position: relative; }
.money::before { content: "€"; position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--gris); }
.money .input { padding-left: 1.7rem; font-family: var(--font-num); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.computed { font-family: var(--font-num); font-size: 1.15rem; padding: .6rem .7rem; border-radius: var(--radius-s); background: var(--sauge); font-variant-numeric: tabular-nums; }

.btn { border: 1px solid var(--trait); background: var(--papier); padding: .55rem 1rem; border-radius: var(--radius-s); cursor: pointer; font-weight: 600; }
a.btn { display: inline-block; text-decoration: none; color: inherit; }
.btn:hover { border-color: var(--foret-2); }
.btn.primary { background: var(--foret); color: #fff; border-color: var(--foret); }
.btn.primary:hover { background: var(--foret-2); }
.btn.danger { color: var(--rouge); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .5rem; }
.seg button { padding: .9rem; border: 2px solid var(--trait); border-radius: var(--radius-m); background: var(--papier); cursor: pointer; font-weight: 600; font-size: 1.05rem; }
.seg button[aria-pressed="true"] { border-color: var(--foret); background: var(--vert-bg); color: var(--foret); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button[aria-pressed="true"] { color: var(--vert); border-color: var(--vert); } }

.status { display: flex; gap: .5rem; align-items: center; padding: .55rem .75rem; border-radius: var(--radius-s); font-weight: 500; margin-top: .75rem; }
.status.ok { background: var(--vert-bg); color: var(--vert); }
.status.ko { background: var(--rouge-bg); color: var(--rouge); }
.status.warn { background: var(--ambre-bg); color: var(--ambre); }
.status.idle { background: var(--sauge); color: var(--gris); }

/* Plateau de comptage : l'élément fort de l'app */
.tray { display: grid; gap: .35rem; }
.coup { display: grid; grid-template-columns: 5.2rem minmax(0, 13rem) 8rem; justify-content: start; align-items: center; gap: .75rem; padding: .3rem 0; border-bottom: 1px dashed var(--trait); }
.coup:last-child { border-bottom: 0; }
.chip { font-family: var(--font-num); font-weight: 700; text-align: center; padding: .35rem 0; border-radius: 4px; color: #1a1a1a; font-size: 1rem; }
.chip.billet { border-radius: 3px; box-shadow: inset 0 0 0 2px rgba(0,0,0,.08); }
.chip.piece { border-radius: 999px; width: 3.2rem; margin: 0 auto; aspect-ratio: 1; display: grid; place-items: center; padding: 0; font-size: .9rem; }
.stepper { display: flex; align-items: center; max-width: 13rem; border: 1px solid var(--trait); border-radius: var(--radius-s); background: var(--papier); }
.stepper button { width: 2.8rem; height: 2.6rem; border: 0; background: none; font-size: 1.35rem; cursor: pointer; color: var(--gris); }
.stepper button:hover { color: var(--encre); background: var(--sauge); }
.stepper input { width: 100%; min-width: 0; border: 0; text-align: center; font-family: var(--font-num); font-size: 1.2rem; background: transparent; }
.sub { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; color: var(--gris); }
.sub.has { color: var(--encre); font-weight: 600; }
.tray-sep { font-size: .85rem; color: var(--gris); margin: .6rem 0 .1rem; }
@media (max-width: 520px) { .coup { grid-template-columns: 4rem 1fr 5.5rem; gap: .5rem; justify-content: stretch; } }

.sticky-total { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--papier); border-top: 1px solid var(--trait);
  padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom, 0px)); }
.sticky-total .in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.big { font-family: var(--font-num); font-size: 1.9rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--vert-bg); color: var(--vert); }
.pill.ko { background: var(--rouge-bg); color: var(--rouge); }
.pill.warn { background: var(--ambre-bg); color: var(--ambre); }
.pill.idle { background: var(--sauge); color: var(--gris); }
.spacer { flex: 1; }
.res-line { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.save-btn { padding: .8rem 1.6rem; font-size: 1.05rem; }
@media (max-width: 560px) {
  .sticky-total .in { flex-wrap: nowrap; gap: .6rem; }
  .sticky-total .big { font-size: 1.45rem; }
  .res-line { gap: .25rem .5rem; }
  .res-line .pill { font-size: .75rem; }
  .save-btn { padding: .75rem .9rem; font-size: .95rem; white-space: normal; line-height: 1.15; max-width: 8.5rem; }
}

/* Tableaux */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; font-weight: 600; color: var(--gris); padding: .5rem .6rem; border-bottom: 2px solid var(--trait); white-space: nowrap; }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--trait); white-space: nowrap; }
td.r, th.r { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--sauge); }
tfoot td { font-weight: 700; border-top: 2px solid var(--trait); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--papier); border: 1px solid var(--trait); border-radius: var(--radius-m); padding: .9rem 1rem; }
.kpi .t { font-size: .88rem; color: var(--gris); }
.kpi .v { font-family: var(--font-num); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .85rem; color: var(--gris); }
.tabs { display: inline-flex; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--radius-s); padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; padding: .45rem .9rem; border-radius: 4px; cursor: pointer; font-weight: 600; color: var(--gris); }
.tabs button[aria-pressed="true"] { background: var(--foret); color: #fff; }
.chart-box { position: relative; height: 320px; }

/* Barre horaire de ponctualité */
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--sauge); margin: .5rem 0; }
.bar span { display: block; }

dialog { border: 1px solid var(--trait); border-radius: var(--radius-m); padding: 0; max-width: min(640px, 94vw); width: 100%; background: var(--papier); color: var(--encre); }
dialog::backdrop { background: rgba(10, 20, 15, .45); }
#modal-body { padding: 1.2rem 1.3rem; max-height: 85vh; overflow: auto; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: .2rem 0; }
.kv-sep { border-top: 1px solid var(--trait); margin: .3rem 0; }
.kv div:nth-child(even) { padding-left: 1rem; text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }

#toast { position: fixed; left: 50%; bottom: 6rem; transform: translateX(-50%); background: var(--encre); color: var(--papier); padding: .6rem 1rem;
  border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }
.done { text-align: center; padding: 2rem 1rem; }
.done .big { font-size: 2.6rem; margin: .5rem 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
