: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; }
.current-sector { min-height: 1.1rem; margin: 0; color: var(--muted); font-size: .8rem; }
.move-validate-button { width: 100%; 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; } }
