:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --paper: #fffdfd;
  --bar: #dedbde;
  --line: #e8e3e6;
  --ink: #171517;
  --muted: #787378;
  --accent: #4d9e50;
  --danger: #b64141;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: #1b1b1b; }
button { font: inherit; }

.app-shell {
  width: min(100%, 30rem);
  min-height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
}

.screen { min-height: 100svh; background: var(--paper); }
.action-bar, .camera-bar {
  min-height: calc(4.35rem + env(safe-area-inset-top));
  padding: calc(.85rem + env(safe-area-inset-top)) 1rem .85rem;
  display: grid;
  grid-template-columns: 4.5rem 1fr 4.5rem;
  align-items: end;
  background: var(--bar);
  border-bottom: 1px solid #d2ced1;
}
.action-bar h1, .camera-bar h1 { margin: 0; font-size: 1rem; font-weight: 500; text-align: center; }
.bar-button { padding: .35rem 0; border: 0; color: #716d71; background: transparent; text-align: left; }
.bar-button.light { color: #fff; }

.menu-screen {
  padding: calc(2.2rem + env(safe-area-inset-top)) 2rem calc(1.5rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}
.brand { margin-top: 1.2rem; display: flex; align-items: center; gap: .9rem; }
.brand-logo {
  width: 76px;
  height: 77px;
  display: block;
  flex: 0 0 auto;
}
.brand strong { display: block; font-size: 1.7rem; letter-spacing: .08em; }
.brand small { color: var(--muted); }
.menu-screen h1 { margin: 2.5rem 0 1.6rem; font-size: 1.35rem; font-weight: 550; }
.menu-actions { width: min(100%, 17rem); display: grid; gap: 1.15rem; }
.menu-button {
  min-height: 3rem;
  border: 1px solid #5f9b62;
  border-radius: .15rem;
  color: #172416;
  background: #9bd399;
  font-weight: 650;
}
.menu-button:not(:disabled):hover { background: #8dca8b; }
.menu-button:not(:disabled):active { transform: translateY(1px); background: #7fbd7e; }
.menu-button:focus-visible { outline: 3px solid rgba(77,158,80,.28); outline-offset: 2px; }
.primary-menu-button { border-color: #4f8d53; background: #8fce8e; }
.menu-button:disabled {
  color: #8e898e;
  border-color: #d3ced2;
  background: #eee9ed;
  font-weight: 400;
  cursor: not-allowed;
}
.menu-hint { max-width: 18rem; margin: 1.5rem 0 0; color: var(--muted); font-size: .82rem; line-height: 1.45; text-align: center; }
.version { margin: auto 0 0; color: #aaa5aa; font-size: .75rem; }

.reserve-screen, .move-screen, .consume-screen, .balance-screen { display: grid; grid-template-rows: auto 1fr; }
.reserve-content, .move-content, .consume-content, .balance-content {
  width: min(100%, 22rem);
  margin: 0 auto;
  padding: 6rem 1.4rem calc(2rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}
.move-content, .consume-content { padding-top: 4.5rem; }
.balance-content { padding-top: 1.5rem; align-items: stretch; }
.move-controls {
  width: 100%;
  margin-top: 1.25rem;
  display: grid;
  gap: .65rem;
}
.move-controls label {
  color: #4d494d;
  font-size: .85rem;
  font-weight: 650;
}
.move-controls select {
  width: 100%;
  min-height: 2.75rem;
  padding: .55rem 2.35rem .55rem .75rem;
  border: 1px solid #aaa5aa;
  border-radius: .2rem;
  color: var(--ink);
  background: #fff;
  font: inherit;
}
.move-controls select:focus { outline: 3px solid rgba(77,158,80,.2); border-color: var(--accent); }
.move-controls select:disabled { color: #999; background: #f0edef; }
.move-validate-button { justify-self: center; margin-top: .35rem; }
.scan-button {
  width: 12.6rem;
  min-height: 2.35rem;
  border: 1px solid #aaa5aa;
  border-radius: .12rem;
  color: #171517;
  background: #d2cfd2;
}
.scan-button:active { background: #c4c0c4; }
.scan-notice {
  width: 100%;
  margin: .85rem 0 0;
  padding: .55rem .75rem;
  border-radius: .3rem;
  color: #27662d;
  background: #eaf6ea;
  font-size: .84rem;
  text-align: center;
}
.scan-notice.error { color: #8c2929; background: #fdecec; }
.result-slot {
  width: 100%;
  min-height: 7rem;
  margin-top: 1rem;
  padding: 1rem;
  display: grid;
  place-content: center;
  border: 1px solid var(--line);
  text-align: center;
}
.slot-label { margin: 0 0 .55rem; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.slot-value { margin: 0; font-size: 1.15rem; font-weight: 600; overflow-wrap: anywhere; }
.slot-value.empty { color: #aaa5aa; font-size: .95rem; font-weight: 400; }
.slot-value:not(.empty) { display: grid; gap: .22rem; }
.detail-line { display: block; color: #3f3b3f; font-size: .94rem; font-weight: 500; line-height: 1.3; }
.detail-title { color: var(--ink); font-size: 1.16rem; font-weight: 700; }
.detail-reference { margin-top: .16rem; color: var(--muted); font-size: .78rem; font-weight: 500; }
.result-slot.filled { border-color: #b8d5b8; background: #fbfffb; }
.result-slot.loading { border-color: #ddd5a9; background: #fffdf3; }
.assignment-label { margin: .5rem 0 -.45rem; color: #4d494d; font-size: .85rem; font-style: italic; }
.reservation-actions {
  width: 100%;
  margin-top: .75rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.consume-actions {
  width: 100%;
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.validate-button, .delete-button {
  width: 7.6rem;
  min-height: 2.5rem;
  border-radius: .12rem;
  font-weight: 650;
}
.balance-button {
  width: 7.6rem;
  min-height: 2.5rem;
  border: 1px solid #aaa5aa;
  border-radius: .12rem;
  color: #3c393c;
  background: #d7d4d7;
  font-weight: 650;
}
.balance-button:active { background: #c9c5c9; }
.balance-button:disabled { color: #999; border-color: #cbc6ca; background: #ebe7ea; }
.balance-form {
  width: 100%;
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
}
.balance-form fieldset { min-width: 0; margin: 0; padding: .85rem; border: 1px solid var(--line); }
.balance-form legend { padding: 0 .35rem; color: #4d494d; font-size: .85rem; font-weight: 650; }
.balance-dimensions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; }
.balance-form label { display: grid; gap: .35rem; color: #4d494d; font-size: .8rem; font-weight: 650; }
.balance-form input, .balance-form select {
  width: 100%;
  min-height: 2.65rem;
  padding: .5rem .6rem;
  border: 1px solid #aaa5aa;
  border-radius: .2rem;
  color: var(--ink);
  background: #fff;
  font: inherit;
}
.balance-form input:focus, .balance-form select:focus {
  outline: 3px solid rgba(77,158,80,.2);
  border-color: var(--accent);
}
.balance-form input:disabled, .balance-form select:disabled { color: #777; background: #f0edef; }
.balance-check-button { width: 100%; }
.balance-stage-note { margin: -.35rem 0 0; color: var(--muted); font-size: .75rem; line-height: 1.4; text-align: center; }
.validate-button {
  border: 1px solid #5dae63;
  color: #173e1b;
  background: #8ee597;
}
.validate-button:active { background: #78d682; }
.validate-button:disabled { color: #718173; border-color: #b8c5b9; background: #dce7dd; }
.delete-button { border: 1px solid #d66a70; color: #631d22; background: #f3979c; }
.delete-button:active { background: #e78086; }
.delete-button:disabled { color: #927679; border-color: #d5bfc1; background: #eadcdd; }

.camera-screen { display: grid; grid-template-rows: auto 1fr; background: #111; }
.camera-bar { color: #fff; background: #1b1d1c; border-bottom-color: rgba(255,255,255,.12); }
.camera-panel { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(circle at 50% 35%, #29302b, #111412 65%); }
.reader, .reader > div, .reader video { width: 100% !important; height: 100% !important; }
.reader { position: absolute; inset: 0; }
.reader video { object-fit: cover !important; }
.reader img { object-fit: contain; }
.scan-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 0 9rem, rgba(0,0,0,.44) 15rem);
}
.scan-overlay p { margin: 1.5rem 0 0; color: #fff; font-weight: 650; text-align: center; text-shadow: 0 1px 8px #000; }
.viewfinder { position: relative; width: min(68vw, 17rem); aspect-ratio: 1; }
.corner { position: absolute; width: 3rem; height: 3rem; border-color: #84dc69; border-style: solid; }
.top-left { inset: 0 auto auto 0; border-width: .28rem 0 0 .28rem; border-radius: 1rem 0 0; }
.top-right { inset: 0 0 auto auto; border-width: .28rem .28rem 0 0; border-radius: 0 1rem 0 0; }
.bottom-left { inset: auto auto 0 0; border-width: 0 0 .28rem .28rem; border-radius: 0 0 0 1rem; }
.bottom-right { inset: auto 0 0 auto; border-width: 0 .28rem .28rem 0; border-radius: 0 0 1rem; }
.scan-line { position: absolute; left: 9%; right: 9%; top: 50%; height: 2px; background: #84dc69; box-shadow: 0 0 12px #84dc69; animation: scan 2.4s ease-in-out infinite; }
@keyframes scan { 0%, 100% { transform: translateY(-5rem); opacity: .45; } 50% { transform: translateY(5rem); opacity: 1; } }
.torch-button, .photo-shortcut {
  position: absolute;
  z-index: 3;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  min-width: 5.8rem;
  padding: .75rem 1rem;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  color: #fff;
  background: rgba(10,12,10,.72);
}
.torch-button { left: 1.25rem; }
.photo-shortcut { right: 1.25rem; }
.camera-fallback {
  position: absolute;
  inset: 0;
  z-index: 4;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  background: #171a18;
}
.camera-fallback h2 { margin: 1.25rem 0 .5rem; }
.camera-fallback p { max-width: 20rem; margin: 0 0 1.5rem; color: #b8beb9; line-height: 1.5; }
.camera-action { width: min(100%, 18rem); min-height: 3rem; border: 0; border-radius: .7rem; color: #10200c; background: #84dc69; font-weight: 700; }
.camera-action.secondary { margin-top: .75rem; color: #fff; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.08); }
.qr-symbol { position: relative; width: 5rem; height: 5rem; border: 2px solid rgba(132,220,105,.5); border-radius: 1rem; }
.qr-symbol span { position: absolute; width: 1.2rem; height: 1.2rem; border: .3rem solid #84dc69; }
.qr-symbol span:nth-child(1) { top: .75rem; left: .75rem; }
.qr-symbol span:nth-child(2) { top: .75rem; right: .75rem; }
.qr-symbol span:nth-child(3) { bottom: .75rem; left: .75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (min-width: 31rem) {
  body { padding: 1.25rem; }
  .app-shell, .screen { min-height: calc(100svh - 2.5rem); }
  .app-shell { max-height: 54rem; border-radius: 1.2rem; box-shadow: 0 24px 70px rgba(0,0,0,.45); }
}
@media (prefers-reduced-motion: reduce) { .scan-line { animation: none; } }

/* Écrans métier : contenu centré avec défilement naturel. */
.reserve-content, .move-content, .consume-content, .balance-content {
  justify-content: center;
  padding-top: 1.5rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}
.reserve-content > *, .move-content > *, .consume-content > *, .balance-content > * { flex-shrink: 0; }
.reserve-screen .scan-button, .move-screen .scan-button, .consume-screen .scan-button, .consume-screen .balance-button:not(:disabled) { background: #b9def6; border-color: #7aaacb; }
.reserve-screen .scan-button:active, .move-screen .scan-button:active, .consume-screen .scan-button:active, .consume-screen .balance-button:not(:disabled):active { background: #9bcceb; }
.reserve-screen .scan-button:disabled, .move-screen .scan-button:disabled, .consume-screen .scan-button:disabled { opacity: .6; }
.reserve-screen .reservation-actions { justify-content: center; }
.reserve-screen .reservation-actions:not(:has(button:not([hidden]))) { display: none; }

/* Présentation commune des scanners Réserver, Déplacer et Consommer. */
.camera-stage { position: absolute; inset: 0; }
.light-camera { background: #fff; }
.light-camera .camera-bar { color: var(--ink); background: var(--bar); border-bottom-color: #d2ced1; }
.light-camera .camera-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  background: #fff;
}
.light-camera .camera-stage {
  position: relative;
  inset: auto;
  width: 100%;
  aspect-ratio: 1;
  flex-shrink: 0;
  overflow: hidden;
  background: #f4f4f4;
}
.light-camera .scan-overlay { display: flex; align-items: center; justify-content: center; background: transparent; }
.light-camera .viewfinder { width: 68%; }
.light-camera .scan-overlay p { position: absolute; bottom: .6rem; margin: 0; color: var(--ink); text-shadow: 0 0 4px #fff, 0 0 4px #fff; }
.light-camera .camera-fallback { padding: 1rem; color: var(--ink); background: #fff; }
.light-camera .camera-fallback h2 { margin: .5rem 0; }
.light-camera .camera-fallback p { margin-bottom: .75rem; color: #4d494d; font-size: .9rem; }
.light-camera .qr-symbol { width: 3.5rem; height: 3.5rem; flex-shrink: 0; }
.light-camera .qr-symbol span { width: .8rem; height: .8rem; border-width: .2rem; }
.camera-abandon { width: 12.6rem; min-height: 2.5rem; flex-shrink: 0; border: 1px solid #aaa5aa; border-radius: .12rem; color: var(--ink); background: #eee9ed; font: inherit; }
.camera-abandon:active { background: #dedbde; }

.menu-screen { position: relative; }
.settings-menu-button { position: absolute; top: calc(.65rem + env(safe-area-inset-top)); left: .65rem; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: .5rem; color: #625d62; background: transparent; border: 0; border-radius: .4rem; }
.settings-menu-button:hover { background: #eee9ed; }
.settings-menu-button:focus-visible { outline: 3px solid #7aaacb; }
.settings-screen { display: grid; grid-template-rows: auto 1fr; }
.settings-content { width: min(100%, 22rem); margin: 0 auto; padding: 1.5rem 1.4rem calc(1.5rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.settings-content > * { flex-shrink: 0; }
.connection-status { margin: 1.25rem 0; }
.connection-icon { display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; background: #eee9ed; color: #625d62; font-size: 1.3rem; font-weight: 700; }
.connection-status[data-state="ok"] .connection-icon { background: #def0dd; color: #27662d; }
.connection-status[data-state="error"] .connection-icon { background: #fdecec; color: #8c2929; }
#connection-message { margin: .6rem 0 .4rem; font-size: 1.15rem; font-weight: 600; }
.connection-detail { margin: 0; font-size: .9rem; line-height: 1.4; color: #625d62; }
.settings-fields { width: 100%; display: grid; gap: .4rem; }
.settings-fields label { text-align: left; font-size: .82rem; color: #625d62; }
.settings-fields input { width: 100%; min-width: 0; padding: .55rem; border: 1px solid #bbb5bb; background: #f6f4f6; color: var(--ink); text-align: center; font: inherit; }
.settings-fields label:not(:first-child) { margin-top: .35rem; }
.settings-hint { color: #787378; font-size: .8rem; line-height: 1.35; }
.settings-version { margin: 1.2rem 0 0; color: #787378; font-size: .78rem; }

.balance-screen .action-bar { grid-template-columns: 7rem 1fr 7rem; }
#balance-back-button { white-space: nowrap; }
.balance-content > .result-slot:first-of-type { margin-top: 0; }

/* Authentification et gestion des accès */
.auth-screen { padding: 24px; display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
.auth-screen > h1 { font-size: 1.55rem; text-align: center; }
.auth-screen > .brand-logo { margin: 24px auto 0; }
.auth-screen > p { line-height: 1.5; }
.auth-screen .action-bar { margin: -24px -24px 12px; flex-shrink: 0; }
.auth-form { display: grid; gap: 20px; width: 100%; }
.auth-form label { display: grid; gap: 8px; font-weight: 600; }
.auth-form input { min-height: 48px; width: 100%; padding: 10px 12px; border: 1px solid #918994; border-radius: 10px; font: inherit; background: white; }
.auth-secondary { min-height: 44px; padding: 10px 14px; border: 1px solid #aaa0a9; border-radius: 10px; background: #fff; color: #302a32; font: inherit; cursor: pointer; }
.auth-secondary:disabled { opacity: .5; cursor: default; }
.auth-notice:empty { display: none; }
.auth-notice { min-height: 24px; color: #63343e; overflow-wrap: anywhere; }
.auth-help { color: #655d67; font-size: .9rem; line-height: 1.5; }
.auth-list { display: grid; gap: 12px; width: 100%; }
.auth-list > button { text-align: left; }
.auth-key { padding: 16px; border: 1px solid #d1c8d1; background: #fff; border-radius: 12px; display: grid; gap: 10px; }
.auth-key p { margin: 0 0 4px; }
.auth-danger { color: #a32032; }
.activation-details { margin: 0; padding: 20px; background: #fff; border-radius: 12px; }
.activation-details dt { font-size: .85rem; color: #655d67; }
.activation-details dd { margin: 4px 0 20px; font-weight: 600; overflow-wrap: anywhere; user-select: all; }
#activation-password { font-family: ui-monospace, monospace; font-size: 1.25rem; }
.session-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; font-size: .9rem; }
[hidden] { display: none !important; }

.auth-access-title { font-size: 1.1rem; margin: 12px 0 0; }
.access-history { border-top: 1px solid #d1c8d1; padding-top: 16px; }
.access-history summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
.access-history > p, .auth-key small { color: #655e65; }
.retired-accesses .auth-key { background: #f6f4f6; }
.home-help-content { max-width: 600px; text-align: left; padding: 12px 0 24px; line-height: 1.5; }
.home-help-icon { display: block; margin: 0 auto 20px; border-radius: 16px; }
.home-help-content h2 { font-size: 1.2rem; margin-top: 24px; }
.home-help-content li { margin: 10px 0; }
#home-help-address { overflow-wrap: anywhere; }

/* Menu centré dans la hauteur disponible, pied de page toujours dans le flux. */
.menu-screen { display: grid; grid-template-rows: 1fr auto; justify-items: center; gap: 1.5rem; padding-top: calc(4rem + env(safe-area-inset-top)); }
.menu-content { width: 100%; display: flex; flex-direction: column; align-items: center; align-self: center; }
.menu-content .brand { margin-top: 0; }
.menu-content h1 { margin-top: 1.75rem; }
.app-footer { width: 100%; margin-top: 1rem; text-align: center; color: #787378; font-size: .75rem; line-height: 1.5; }
.app-footer p { margin: .15rem 0; }
.app-footer .app-dsn { font-size: .68rem; overflow-wrap: anywhere; }

.home-button { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.camera-bar h1 { line-height: 1.3; }
