:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #17212b;
  --muted: #6d7782;
  --line: #dde3e8;
  --accent: #1457d9;
  --accent-soft: #eef4ff;
  --success: #167746;
  --danger: #a52a20;
  --shadow: 0 14px 48px rgba(23, 33, 43, .09);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .1em; font-size: .68rem; font-weight: 900; color: var(--accent); }
h1, h2, p { margin-top: 0; }
h1, h2 { margin-bottom: 0; letter-spacing: -.025em; }

.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at top, #fff 0, var(--bg) 58%); }
.login-card { width: min(100%, 540px); padding: 28px; border: 1px solid var(--line); border-radius: 28px; background: rgba(255,255,255,.96); box-shadow: var(--shadow); }
.login-logo { width: 56px; height: 56px; margin-bottom: 18px; display: grid; place-items: center; border-radius: 18px; background: var(--accent-soft); color: var(--accent); font-size: 1.7rem; font-weight: 900; }
.login-card h1 { font-size: clamp(1.75rem, 7vw, 2.35rem); }
.login-help { margin: 10px 0 22px; color: var(--muted); line-height: 1.5; }
.profile-list { display: grid; gap: 10px; }
.profile-choice { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 13px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: #fff; color: var(--text); text-align: left; }
.profile-choice:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.profile-choice strong, .profile-choice small { display: block; }
.profile-choice small { margin-top: 3px; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.profile-avatar { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 900; }
.profile-arrow { color: var(--muted); font-size: 1.8rem; }
.loading { padding: 18px; text-align: center; color: var(--muted); }

.app-shell { width: min(100%, 920px); min-height: 100dvh; margin: 0 auto; display: grid; grid-template-rows: auto auto minmax(260px, 40vh) minmax(380px, 1fr); background: var(--bg); }
.store-strip { position: sticky; top: 0; z-index: 20; min-height: 62px; display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 10px; align-items: center; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(12px); }
.brand-mini { border: 0; background: transparent; display: inline-flex; align-items: center; gap: 7px; padding: 0; color: var(--text); font-size: .8rem; font-weight: 850; white-space: nowrap; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.store-tabs { min-width: 0; display: flex; justify-content: center; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.store-tabs::-webkit-scrollbar { display: none; }
.store-tab { min-height: 38px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-size: .82rem; font-weight: 850; white-space: nowrap; }
.store-tab.active { border-color: var(--accent); background: var(--accent); color: #fff; box-shadow: 0 5px 15px color-mix(in srgb, var(--accent) 24%, transparent); }
.header-actions { display: flex; align-items: center; gap: 7px; }
.connection-state { color: #2ba05c; font-size: .72rem; }
.connection-state.offline { color: #d46d1d; }
.user-chip { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 900; }
.install-pwa-btn { min-height: 34px; display: inline-flex; align-items: center; gap: 5px; padding: 7px 10px; border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .76rem; font-weight: 850; }

.admin-context { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 10px 0; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: 14px; background: var(--accent-soft); color: var(--text); font-size: .82rem; }
.admin-context button { border: 0; background: transparent; color: var(--accent); font-weight: 850; }

.panel { margin: 10px 10px 0; padding: 18px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: 0 7px 24px rgba(23,33,43,.04); overflow: hidden; }
.loyalty-panel { display: flex; flex-direction: column; justify-content: center; }
.voucher-panel { margin-bottom: 12px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 13px; }
.panel-heading h1, .panel-heading h2 { font-size: clamp(1.15rem, 5vw, 1.45rem); }
.icon-btn, .close-btn { flex: 0 0 auto; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 13px; background: #fff; color: var(--text); font-weight: 900; }
.close-btn { font-size: 1.45rem; line-height: 1; }
.empty-state { min-height: 150px; display: grid; place-items: center; align-content: center; gap: 7px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); }
.empty-state p { max-width: 410px; margin: 0 0 6px; font-size: .86rem; line-height: 1.45; }
.empty-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: var(--accent-soft); color: var(--accent); font-size: 1.5rem; font-weight: 900; }

/* Code-barres : volontairement centrés sur les deux panneaux. */
.barcode-card { width: 100%; border: 0; border-radius: 19px; background: #fff; color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 10px 8px; overflow: hidden; }
.barcode-stage { width: 100%; min-height: 96px; display: flex; align-items: center; justify-content: center; padding: 8px 16px; background: #fff; }
.barcode-img { display: block; width: min(100%, 540px); height: 98px; object-fit: contain; object-position: center; margin: 0 auto; }
.number-text { display: block; width: 100%; text-align: center; font-size: clamp(.95rem, 4vw, 1.2rem); font-weight: 900; letter-spacing: .07em; overflow-wrap: anywhere; }
.tap-hint { color: var(--muted); font-size: .72rem; font-weight: 700; }

.voucher-content { display: flex; flex-direction: column; gap: 11px; }
.voucher-details { border: 1px solid var(--line); border-radius: 17px; overflow: hidden; }
.detail-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: 0; }
.detail-row span { color: var(--muted); font-size: .85rem; }
.detail-row strong { text-align: right; overflow-wrap: anywhere; }
.pin-button { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 7px 10px; font-weight: 900; letter-spacing: .08em; }
.queue-badge { align-self: center; padding: 7px 11px; border-radius: 999px; background: #f0f2f4; color: #53606c; font-size: .78rem; font-weight: 800; }
.voucher-actions { display: grid; gap: 8px; }

.primary-btn, .secondary-btn, .success-btn, .mode-btn { min-height: 46px; border-radius: 14px; padding: 10px 14px; font-weight: 850; }
.primary-btn { border: 0; background: var(--accent); color: #fff; }
.secondary-btn { border: 1px solid var(--line); background: #fff; color: var(--text); }
.success-btn { border: 0; background: #e9f7ef; color: var(--success); }
.mode-btn { border: 1px solid var(--line); background: #f8f9fa; color: var(--text); text-align: center; }
.full { width: 100%; }
.danger-link { border: 0; background: transparent; color: var(--danger); font-weight: 850; padding: 8px; }

.modal { width: min(calc(100% - 22px), 650px); max-height: min(92dvh, 860px); padding: 0; border: 0; border-radius: 26px; background: transparent; }
.compact-modal { width: min(calc(100% - 22px), 520px); }
.modal::backdrop, .fullscreen-code::backdrop, .image-modal::backdrop { background: rgba(10,17,24,.58); backdrop-filter: blur(5px); }
.modal-card { margin: 0; padding: 20px; border: 0; border-radius: 26px; background: #fff; display: grid; gap: 14px; max-height: 92dvh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal label { display: grid; gap: 7px; color: #37424d; font-size: .85rem; font-weight: 750; }
.modal input, .modal select { width: 100%; min-height: 48px; border: 1px solid #d7dde2; border-radius: 13px; padding: 10px 12px; background: #fff; color: var(--text); outline: none; }
.modal input:focus, .modal select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check-line { display: flex !important; grid-template-columns: none; align-items: center; gap: 9px !important; }
.check-line input { width: 20px; min-height: 20px; accent-color: var(--accent); }
.optional { color: var(--muted); font-size: .72rem; font-weight: 600; }
.import-grid { display: grid; gap: 9px; }
.two-modes { grid-template-columns: repeat(2, 1fr); }
.three-modes { grid-template-columns: repeat(3, 1fr); }
.file-btn { display: grid !important; place-items: center; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-note { margin: -4px 0 0; color: var(--muted); font-size: .76rem; text-align: center; }

.camera-box { position: relative; border-radius: 18px; overflow: hidden; background: #111; padding-bottom: 10px; }
.camera-box video { width: 100%; min-height: 230px; max-height: 360px; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 8%; right: 8%; top: 22%; height: 42%; border: 2px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: inset 0 0 0 999px rgba(0,0,0,.12); pointer-events: none; }
.scan-frame::after { content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 9px #ff3b30; }
.camera-box .secondary-btn { display: block; margin: 10px auto 0; }
.ocr-status { padding: 10px 12px; border-radius: 13px; background: var(--accent-soft); color: var(--accent); font-size: .83rem; font-weight: 750; line-height: 1.4; }
.voucher-preview { width: 100%; max-height: 260px; object-fit: contain; border: 1px solid var(--line); border-radius: 15px; background: #f6f7f8; }

.menu-list { display: grid; gap: 7px; }
.menu-item { width: 100%; min-height: 50px; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); text-align: left; font-weight: 800; }
.menu-item b { color: var(--muted); font-size: 1.4rem; }
.management-list, .history-list, .voucher-list { display: grid; gap: 9px; }
.management-item, .history-item, .voucher-list-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 15px; }
.management-item.inactive { opacity: .55; }
.management-item strong, .history-item strong, .voucher-list-item strong { display: block; overflow-wrap: anywhere; }
.management-item small, .history-item small, .voucher-list-item small { display: block; margin-top: 3px; color: var(--muted); }
.item-actions { display: flex; gap: 5px; align-items: center; }
.mini-btn { min-height: 34px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); padding: 6px 9px; font-size: .76rem; font-weight: 800; }
.voucher-list-item.active-first { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.status-pill { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; background: #eef1f3; color: var(--muted); font-size: .7rem; font-weight: 850; }
.status-pill.active { background: #e9f7ef; color: var(--success); }

.fullscreen-code, .image-modal { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #fff; }
.fullscreen-inner { height: 100%; padding: 70px 18px 32px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 18px; text-align: center; }
.fullscreen-inner p { margin: 0; color: var(--muted); font-weight: 800; }
.fullscreen-barcode-stage { width: min(96vw, 920px); min-height: 220px; display: flex; align-items: center; justify-content: center; background: #fff; padding: 14px; }
.fullscreen-inner img { display: block; width: min(94vw, 880px); height: min(34vh, 300px); object-fit: contain; object-position: center; margin: 0 auto; }
.fullscreen-inner strong { font-size: clamp(1.2rem, 6vw, 2.15rem); letter-spacing: .08em; overflow-wrap: anywhere; }
.fullscreen-close { position: fixed; z-index: 3; top: calc(14px + env(safe-area-inset-top)); right: 14px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: #eef1f3; color: #111; font-size: 1.65rem; }
.image-modal { background: #0a0d10; }
.image-modal img { width: 100%; height: 100%; object-fit: contain; padding: 72px 12px 20px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 18px); max-width: calc(100% - 30px); padding: 11px 15px; border-radius: 14px; background: #17212b; color: #fff; font-size: .86rem; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: 0 12px 40px rgba(0,0,0,.24); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8d1b12; }

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app-shell { min-height: calc(100dvh - 36px); border-radius: 30px; overflow: hidden; box-shadow: 0 24px 80px rgba(23,33,43,.12); }
  .store-strip { position: relative; }
  .panel, .admin-context { margin-left: 20px; margin-right: 20px; }
}
@media (max-width: 560px) {
  .three-modes { grid-template-columns: 1fr; }
  .install-pwa-label { display: none; }
  .install-pwa-btn { width: 36px; padding: 0; justify-content: center; }
}
@media (max-width: 430px) {
  .brand-mini span:last-child { display: none; }
  .store-strip { grid-template-columns: auto minmax(0,1fr) auto; padding-left: 9px; padding-right: 9px; }
  .panel { margin-left: 8px; margin-right: 8px; padding: 15px; border-radius: 20px; }
  .two-cols, .two-modes { grid-template-columns: 1fr; }
  .login-screen { padding: 13px; }
  .login-card { padding: 22px 16px; border-radius: 22px; }
  .profile-choice { padding: 12px; }
  .barcode-stage { padding-left: 4px; padding-right: 4px; }
  .barcode-img { height: 88px; }
  .management-item { grid-template-columns: 1fr; }
  .item-actions { justify-content: flex-start; }
}

/* ===== V2 : multi-utilisateurs, administration et centrage des codes ===== */
.brand-mini { border: 0; background: transparent; padding: 6px 2px; }
.muted { color: var(--muted); }
.loading, .empty-inline { padding: 18px 10px; text-align: center; color: var(--muted); font-size: .9rem; }

/* Le SVG peut avoir une largeur intrinsèque variable : le centrage est porté par ce stage. */
.barcode-stage,
.fullscreen-barcode-stage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: #fff;
}
.barcode-stage { min-height: 112px; border-radius: 12px; padding: 4px 10px; }
.barcode-img {
  display: block;
  width: auto;
  max-width: 100%;
  height: 108px;
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
}
.number-text { width: 100%; text-align: center; }
.fullscreen-barcode-stage { min-height: min(38vh, 320px); padding: 12px; }
.fullscreen-inner img {
  display: block;
  width: auto;
  max-width: min(96vw, 900px);
  height: min(34vh, 280px);
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
}

.admin-context {
  margin: 10px 14px 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 15px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
}
.admin-context button {
  border: 0;
  border-radius: 10px;
  padding: 7px 10px;
  background: #fff;
  color: var(--accent);
  font-weight: 850;
  white-space: nowrap;
}

.menu-list { display: grid; gap: 8px; }
.menu-item {
  min-height: 52px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  text-align: left;
  font-weight: 800;
}
.menu-item span:first-child { text-align: center; }
.menu-item b { color: var(--muted); font-size: 1.25rem; }
.menu-item:hover { background: #f8f9fa; }

.management-list, .history-list { display: grid; gap: 10px; }
.management-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.management-item.is-inactive { opacity: .62; background: #f7f8f9; }
.management-info { min-width: 0; }
.management-info strong, .management-info small { display: block; }
.management-info strong { overflow-wrap: anywhere; }
.management-info small { margin-top: 4px; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.management-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.mini-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  background: #f8f9fa;
  color: var(--text);
  font-size: .75rem;
  font-weight: 850;
}
.mini-btn.danger { color: var(--danger); background: #fff7f6; border-color: #f0d1ce; }

.check-line { grid-template-columns: auto 1fr !important; align-items: center; justify-content: start; }
.check-line input { width: 20px !important; min-height: 20px !important; height: 20px; margin: 0; }
.two-modes { grid-template-columns: 1fr 1fr; }

.history-item {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
.history-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.history-id { margin: 7px 0 5px; font-weight: 800; overflow-wrap: anywhere; }
.history-item small { color: var(--muted); }
.status-badge { padding: 5px 8px; border-radius: 999px; font-size: .68rem; font-weight: 900; }
.status-badge.active { background: #eaf7ef; color: var(--success); }
.status-badge.used { background: #f0f2f4; color: #5c6670; }

.scan-frame {
  position: absolute;
  left: 8%; right: 8%; top: 24%; height: 45%;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.14), inset 0 0 0 1px rgba(0,0,0,.12);
  pointer-events: none;
}
.scan-frame::after {
  content: '';
  position: absolute;
  left: 7%; right: 7%; top: 50%;
  height: 2px;
  background: #ff453a;
  box-shadow: 0 0 10px #ff453a;
}

@media (max-width: 560px) {
  .management-item { grid-template-columns: 1fr; }
  .management-actions { justify-content: flex-start; }
}

@media (max-width: 420px) {
  .admin-context { margin-left: 8px; margin-right: 8px; }
  .barcode-stage { padding-left: 4px; padding-right: 4px; }
}

/* V2.0.1 — destinataire explicite des bons ajoutés par l'administrateur */
.recipient-hint {
  margin-top: -7px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  text-align: left;
  font-weight: 750;
}
#voucherRecipientSelect { font-weight: 800; }
