:root {
  --bg: #f2f5fb; --surface: #ffffff; --ink: #0d1a33; --muted: #5a6a86; --line: #dde5f2;
  --primary: #14397f; --primary-2: #2a64d8; --on-primary: #ffffff; --tint: #e6eefc; --tint-ink: #14397f;
  --ok: #107a57; --ok-bg: #e3f5ee; --warn: #a64b06; --warn-bg: #fff2e0; --danger: #c0261d; --danger-bg: #fdeceb;
  --red: #e1000f; --shadow: 0 1px 2px rgba(13, 26, 51, .06), 0 8px 24px rgba(13, 26, 51, .07);
  --r: 20px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1121; --surface: #121b30; --ink: #eaf0fb; --muted: #93a3c0; --line: #22314f;
    --primary: #3b74ea; --primary-2: #6b9bff; --tint: #1a2a4c; --tint-ink: #b9cffd;
    --ok: #4cc9a0; --ok-bg: #11332b; --warn: #ffb36b; --warn-bg: #3a2a14; --danger: #ff8a82; --danger-bg: #3b1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app { max-width: 560px; height: 100%; margin: 0 auto; display: flex; flex-direction: column; position: relative; }
#screen { flex: 1; overflow-y: auto; padding: 0 16px calc(24px + var(--safe-b)); scroll-behavior: smooth; }
.appbar { position: sticky; top: 0; z-index: 5; margin: 0 -16px 12px; padding: 12px 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); display: flex; align-items: center; gap: 10px; }
.appbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
.appbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary) 0 33%, var(--surface) 33% 66%, var(--red) 66%); opacity: .0; }
.iconbtn { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); }
.iconbtn:active { transform: scale(.95); }

/* Hero / marque */
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 0 6px; }
.logo { width: 46px; height: 46px; border-radius: 14px; background: linear-gradient(145deg, var(--primary), var(--primary-2)); color: #fff; display: grid; place-items: center; }
.brand b { font-size: 18px; } .brand small { display: block; color: var(--muted); }
.hero { background: linear-gradient(150deg, var(--primary), var(--primary-2)); color: #fff; border-radius: 26px; padding: 20px; margin: 8px 0 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255, 255, 255, .09); }
.hero .lbl { opacity: .8; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
.hero .big { font-size: 38px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 10px; }
.hero .row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: rgba(255, 255, 255, .18); }
.pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.tint { background: var(--tint); color: var(--tint-ink); } .pill.danger { background: var(--danger-bg); color: var(--danger); }

/* Tuiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--surface); border-radius: var(--r); padding: 16px; min-height: 118px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; box-shadow: var(--shadow); position: relative; transition: transform .12s; }
.tile:active { transform: scale(.97); }
.tile .ico { width: 44px; height: 44px; border-radius: 14px; background: var(--tint); color: var(--tint-ink); display: grid; place-items: center; }
.tile b { display: block; font-size: 16px; line-height: 1.2; } .tile small { color: var(--muted); }
.tile.wide { grid-column: span 2; flex-direction: row; align-items: center; min-height: 0; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.tile.wide .ico { background: rgba(255, 255, 255, .2); color: #fff; } .tile.wide small { color: rgba(255, 255, 255, .8); }
.badge[hidden] { display: none; }
.badge { position: absolute; top: 12px; right: 12px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--red); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; }

/* Cartes, listes */
.card { background: var(--surface); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); width: 100%; text-align: left; }
.item:active { transform: scale(.985); }
.item .grow { flex: 1; min-width: 0; } .item b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item small, .muted { color: var(--muted); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--tint); color: var(--tint-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.item.sel { outline: 2.5px solid var(--primary-2); background: var(--tint); } .item.sel .avatar { background: var(--primary); color: #fff; }
.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; display: flex; justify-content: space-between; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px; border-radius: 16px; font-weight: 650; background: var(--tint); color: var(--tint-ink); }
.btn.primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.danger { background: var(--danger-bg); color: var(--danger); } .btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.block { width: 100%; } .btn:disabled { opacity: .45; } .btn:active { transform: scale(.98); }
.btnrow { display: flex; gap: 10px; margin-top: 14px; } .btnrow > * { flex: 1; }
.fab-bar { position: sticky; bottom: 0; margin: 14px -16px 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 28%); }

/* Formulaires */
.field { display: block; margin-bottom: 12px; } .field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px 4px; font-weight: 600; }
.input { width: 100%; min-height: 52px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); outline: none; }
.input:focus { border-color: var(--primary-2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary-2) 18%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .grid3 { display: grid; grid-template-columns: 2fr 1fr 1.2fr; gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 10px 4px; gap: 12px; }
.switch input { width: 48px; height: 28px; accent-color: var(--primary); }
.hint { font-size: 13px; color: var(--muted); margin: -4px 4px 12px; }
.err { color: var(--danger); font-weight: 600; min-height: 22px; text-align: center; }

/* Stepper */
.steps { display: flex; gap: 6px; margin: 0 0 16px; } .steps i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps i.on { background: var(--primary-2); } .steps i.done { background: var(--primary); }
.h2 { font-size: 24px; letter-spacing: -.02em; margin: 4px 0 4px; } .lead { color: var(--muted); margin: 0 0 18px; }
.datecard { position: relative; display: flex; align-items: center; gap: 14px; background: var(--surface); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.datecard .ico { width: 44px; height: 44px; border-radius: 14px; background: var(--tint); color: var(--tint-ink); display: grid; place-items: center; }
.datecard b { display: block; font-size: 18px; } .datecard input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; }
.dtrow { display: grid; grid-template-columns: 1.6fr 1fr; gap: 10px; margin-bottom: 10px; }
.timegrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px; }
.timegrid button { height: 46px; border-radius: 12px; background: var(--tint); color: var(--tint-ink); font-weight: 650; font-variant-numeric: tabular-nums; }
.timegrid button.on { background: var(--primary); color: #fff; }

/* Chips & filtres */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; }
.chip.on { background: var(--primary); color: #fff; }
.monthbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthbar b { font-size: 18px; text-transform: capitalize; }

/* Tickets */
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.thumb { aspect-ratio: 3 / 4; border-radius: 16px; background: var(--tint) center / cover; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.thumb .st { position: absolute; left: 6px; right: 6px; bottom: 6px; padding: 3px 6px; border-radius: 10px; font-size: 12px; font-weight: 700; text-align: center; background: rgba(255, 255, 255, .92); color: var(--ink); }
.thumb .st.ok { background: var(--ok); color: #fff; } .thumb .st.warn { background: var(--warn-bg); color: var(--warn); }
.capture { aspect-ratio: 3 / 4; border-radius: 16px; border: 2px dashed var(--primary-2); color: var(--primary-2); display: grid; place-items: center; text-align: center; font-weight: 650; padding: 8px; gap: 4px; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary-2); animation: spin 0.9s linear infinite; margin: auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.flag { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 14px; margin-bottom: 8px; font-size: 14px; font-weight: 550; }
.flag.warn { background: var(--warn-bg); color: var(--warn); } .flag.info { background: var(--tint); color: var(--tint-ink); }
.receipt { width: 100%; max-height: 38vh; object-fit: contain; border-radius: 16px; background: #000; display: block; margin-bottom: 12px; }

/* Tableau synthèse */
.tablewrap { overflow-x: auto; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); margin-bottom: 14px; }
table.sum { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 13px; }
table.sum th { background: var(--tint); color: var(--tint-ink); text-align: center; padding: 10px 8px; font-size: 12px; position: sticky; top: 0; }
table.sum td { padding: 10px 8px; border-top: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.sum td.l, table.sum th.l { text-align: left; position: sticky; left: 0; background: var(--surface); } table.sum th.l { background: var(--tint); }
table.sum tfoot td { font-weight: 800; background: var(--tint); }

/* PIN */
.pinwrap { text-align: center; padding-top: 18px; }
.dots { display: flex; justify-content: center; gap: 16px; margin: 20px 0 6px; } .dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary-2); }
.dots i.on { background: var(--primary-2); } .dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 18px auto 0; }
.pad button { height: 68px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); font-size: 26px; font-weight: 600; display: grid; place-items: center; }
.pad button:active { background: var(--tint); transform: scale(.96); }

/* Sheets, toasts */
#sheets { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.backdrop { position: absolute; inset: 0; background: rgba(6, 12, 28, .5); opacity: 0; transition: opacity .2s; pointer-events: auto; }
.sheet { position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 100%); width: min(560px, 100%); max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 28px 28px 0 0; padding: 10px 16px calc(20px + var(--safe-b)); transition: transform .28s cubic-bezier(.2, .9, .3, 1); pointer-events: auto; }
.sheet.open { transform: translate(-50%, 0); } .backdrop.open { opacity: 1; }
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 20px; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(24px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 40; pointer-events: none; }
.toast { background: #0d1a33; color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 600; box-shadow: var(--shadow); max-width: 90%; animation: pop .25s; }
.toast.err { background: var(--danger); } @keyframes pop { from { transform: translateY(12px); opacity: 0; } }
.offline { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 14px; margin-bottom: 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.btnrow .btn { padding: 0 10px; font-size: 15px; line-height: 1.15; text-align: center; }

/* Mentions à recopier sur le ticket papier */
.annot { border: 2px solid var(--primary-2); border-radius: 18px; padding: 12px 14px; margin-bottom: 12px; background: var(--tint); display: grid; gap: 6px; }
.annot-h { font-weight: 700; color: var(--tint-ink); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .annot-h span { font-weight: 500; opacity: .75; font-size: 13px; }
.annot small { display: block; color: var(--muted); font-size: 12px; } .annot b { font-size: 17px; letter-spacing: .01em; word-break: break-word; }
details summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 4px; } details summary::-webkit-details-marker { display: none; }
/* Doublon */
.dupgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.dupcol { background: var(--surface); border-radius: 16px; padding: 10px; text-align: center; font-size: 14px; display: grid; gap: 4px; box-shadow: var(--shadow); }
.dupcol img { width: 100%; height: 150px; object-fit: cover; border-radius: 10px; } .dupnoimg { height: 150px; display: grid; place-items: center; color: var(--muted); background: var(--tint); border-radius: 10px; }
/* Caméra intégrée */
.cam { position: fixed; inset: 0; z-index: 60; background: #000; }
.cam video { width: 100%; height: 100%; object-fit: cover; }
.cam-frame { position: absolute; inset: 14% 10% 22%; border: 2px dashed rgba(255, 255, 255, .55); border-radius: 18px; pointer-events: none; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 12px; display: flex; justify-content: space-between; align-items: center; color: #fff; background: linear-gradient(rgba(0, 0, 0, .55), transparent); }
.cam-top .btn { min-height: 42px; background: rgba(255, 255, 255, .92); color: #0d1a33; }
.cam-bottom { position: absolute; bottom: 0; left: 0; right: 0; padding: 18px 16px calc(24px + var(--safe-b)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.cam-shutter { width: 78px; height: 78px; border-radius: 50%; background: #fff; border: 6px solid rgba(255, 255, 255, .45); background-clip: padding-box; }
.cam-shutter:active { transform: scale(.92); } .cam-count { color: #fff; font-weight: 700; text-align: right; font-size: 14px; }
.cam-torch { width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 255, 255, .22); color: #fff; display: grid; place-items: center; }
.cam.flash video { opacity: .35; }
[hidden] { display: none !important; }
.linkbtn { background: none; border: 0; padding: 6px 10px; color: var(--muted, #6b7280); font-size: 13px; text-decoration: underline; cursor: pointer; }
.hint .linkbtn { color: var(--primary-2); font-size: inherit; padding: 0 2px; }
.copy { text-align: center; color: var(--muted); font-size: 11px; padding: 18px 0 calc(22px + var(--safe-b)); opacity: .8; }
.prog { margin: 0 0 14px; } .prog .bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.prog .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 6px; transition: width .4s; }
.prog small { display: block; margin-top: 6px; color: var(--muted); }
.memo { font-size: 12px; color: var(--muted); text-align: center; margin: -4px 0 10px; word-break: break-word; }
