:root {
  --bg: #152028;
  --bg-idle: #1a2832;
  --bg-success: #0f5c2e;
  --bg-error: #8b1e1e;
  --bg-attention: #8a6d12;
  --text: #f4f7f5;
  --muted: #c4d0c8;
  --accent: #d4ecc8;
  --input-bg: #223240;
  --font-display: "Segoe UI", "Trebuchet MS", sans-serif;
  --font-body: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  overflow: hidden;
}

#app {
  height: 100%;
  max-height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  position: relative;
}

.dismiss-scan {
  position: fixed;
  top: 0.45rem;
  left: 0.45rem;
  z-index: 30;
  background: #ffffff;
  padding: 0.4rem 0.5rem 0.3rem;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  text-align: center;
  line-height: 1;
}

.dismiss-scan img {
  display: block;
  width: 200px;
  height: auto;
  image-rendering: pixelated;
}

.dismiss-scan-label {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: #111;
  letter-spacing: 0.02em;
}

.modebar {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.1rem 1.4rem 1.3rem;
  background: rgba(0,0,0,0.28);
  z-index: 6;
}

.modes {
  display: flex;
  gap: 1.8rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.5rem 0.55rem 0.65rem;
  border-radius: 18px;
  border: 2px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.07);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.mode-card:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.28);
}

.mode-card.active {
  background: var(--accent);
  color: #102018;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 236, 200, 0.28);
}

.mode-qr {
  flex: 0 0 auto;
  background: #fff;
  padding: 7px;
  border-radius: 12px;
  line-height: 0;
}

.mode-qr img {
  display: block;
  width: 129px;
  height: 129px;
  pointer-events: none;
  user-select: none;
}

.mode-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  align-items: center;
}

.mode-name {
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

.mode-hint {
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.72;
}

.mode-card.active .mode-hint {
  opacity: 0.78;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
  position: absolute;
  right: 1rem;
  top: 0.7rem;
  z-index: 15;
}

.dry-badge {
  background: #c9a227;
  color: #1a1400;
  font-weight: 700;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.linkish {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.9rem;
}

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  transition: background 0.15s ease;
  min-height: 0;
  overflow: auto;
}

.screen.has-picker {
  justify-content: flex-start;
}

.screen.idle {
  background: radial-gradient(ellipse at 50% 28%, #2a4250 0%, var(--bg-idle) 68%);
}
.screen.success { background: var(--bg-success); }
.screen.error { background: var(--bg-error); }
.screen.attention { background: var(--bg-attention); }

.mode-label {
  font-size: clamp(1.25rem, 2.6vw, 1.75rem);
  letter-spacing: 0.02em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.prompt {
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 700;
  margin: 0.4rem 0 1rem;
}

.screen.has-picker .mode-label {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.screen.has-picker .prompt {
  font-size: clamp(1.15rem, 2.2vw, 1.7rem);
  margin: 0.2rem 0 0.5rem;
}

.context {
  font-size: clamp(1.2rem, 3vw, 2rem);
  color: var(--accent);
  min-height: 1.5em;
}

.result-title {
  font-size: clamp(2.8rem, 9vw, 6.5rem);
  font-weight: 800;
  line-height: 1.05;
  margin: 0.2rem 0;
}

.result-shelf {
  font-size: clamp(2rem, 6vw, 4.2rem);
  font-weight: 700;
  margin: 0.3rem 0 1rem;
}

.result-order {
  font-size: clamp(1.8rem, 4.5vw, 3.2rem);
  font-weight: 700;
}

.result-order a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.14em;
  cursor: pointer;
}

.result-order a:hover,
.result-order a:focus-visible {
  opacity: 0.85;
}

.result-agent {
  font-size: clamp(1.2rem, 3vw, 2rem);
  margin-top: 0.3rem;
}

.result-status {
  font-size: clamp(1.1rem, 2.5vw, 1.8rem);
  margin-top: 1rem;
  font-weight: 600;
}

.result-details {
  margin-top: 1rem;
  font-size: clamp(1rem, 2.2vw, 1.5rem);
  max-width: 40rem;
  line-height: 1.35;
}

.result-reason {
  margin-top: 1rem;
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 600;
  max-width: none;
  white-space: nowrap;
}

.result-time {
  margin-top: 1.5rem;
  font-size: 1rem;
  color: rgba(255,255,255,0.75);
}

#scanForm {
  padding: 0.85rem 1.2rem 1.15rem;
  background: rgba(0,0,0,0.32);
}

#scanInput {
  width: 100%;
  font-size: 1.35rem;
  padding: 0.9rem 1.1rem;
  border: 2px solid rgba(255,255,255,0.16);
  border-radius: 14px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}

#scanInput:focus {
  border-color: var(--accent);
}

.session {
  margin-top: 1rem;
  width: min(40rem, 100%);
}

.session-title {
  font-size: 2rem;
  font-weight: 700;
}

.session-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  text-align: left;
  font-size: 1.4rem;
}

.session-list li { padding: 0.2rem 0; }

.session-total {
  font-size: 1.6rem;
  font-weight: 700;
}

.manual {
  margin-top: 1rem;
  width: min(100%, 96rem);
}

.manual-title {
  font-size: 1.15rem;
  margin-bottom: 0.55rem;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.5rem;
}

.courier-grid,
.scan-grid,
.manual-grid.scan-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  justify-content: center;
  align-items: stretch;
  gap: 1.25rem 1.8rem;
  width: 100%;
  max-width: min(100%, 96rem);
}

.scan-card,
.manual-grid .courier-card,
.manual-grid .scan-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  flex: 1 1 0;
  min-width: 0;
  max-width: 9.6rem;
  padding: 0.45rem 0.35rem 0.5rem;
  border: 2px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.07);
  color: var(--text);
  cursor: pointer;
  border-radius: 12px;
}

.manual-grid.scan-grid .scan-card,
.scan-grid .scan-card {
  flex: none;
  min-width: 0;
  max-width: none;
  width: 100%;
  gap: 0.55rem;
  padding: 0.7rem 0.55rem 0.85rem;
}

.scan-card:hover,
.manual-grid .courier-card:hover,
.manual-grid .scan-card:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.28);
}

.scan-card.active,
.manual-grid .courier-card.active,
.manual-grid .scan-card.active {
  background: var(--accent);
  color: #102018;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 236, 200, 0.28);
}

.scan-card-danger {
  border-color: rgba(255, 160, 160, 0.55);
  background: rgba(92, 16, 16, 0.45);
}

.scan-qr,
.courier-qr {
  background: #fff;
  padding: 4px;
  border-radius: 8px;
  line-height: 0;
  width: 100%;
}

.manual-grid.scan-grid .scan-qr,
.scan-grid .scan-qr {
  padding: 16px;
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  box-sizing: border-box;
}

.scan-qr img,
.courier-qr img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  pointer-events: none;
  user-select: none;
}

.manual-grid.scan-grid .scan-qr img,
.scan-grid .scan-qr img {
  width: 100%;
  height: auto;
  max-width: 420px;
  aspect-ratio: 1;
  image-rendering: crisp-edges;
}

.scan-name,
.courier-name {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session .scan-card {
  flex: 0 0 auto;
  margin: 0.8rem auto 0;
  max-width: 9.6rem;
}

.actions .scan-card {
  flex: 0 0 auto;
  max-width: 9.6rem;
}

.btn, .manual-grid button:not(.scan-card) {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  padding: 0.7rem 1.1rem;
  font-size: 1.05rem;
  cursor: pointer;
  border-radius: 12px;
}

.btn.primary {
  background: var(--accent);
  color: #102018;
  border-color: var(--accent);
  margin-top: 0.8rem;
}

.btn.danger {
  background: #5c1010;
}

.actions {
  display: flex;
  gap: 1.6rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
  justify-content: center;
}

#dismissBtn {
  font-size: inherit;
}

.debug {
  position: fixed;
  right: 0;
  top: 2.4rem;
  width: min(28rem, 100%);
  max-height: 45vh;
  overflow: auto;
  background: #0b1016;
  border-left: 1px solid rgba(255,255,255,0.15);
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding: 0.8rem;
  font-size: 0.75rem;
  z-index: 20;
}

.debug pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.diag-body { overflow: auto; }
.diag { padding: 2rem; max-width: 60rem; margin: 0 auto; }
.diag pre {
  background: #0b1016;
  padding: 1rem;
  overflow: auto;
}

@media (max-width: 980px) {
  .modebar { padding-left: 1rem; padding-right: 1rem; }
  .modes { gap: 0.9rem; }
  .mode-qr img { width: 80px; height: 80px; }
  .mode-name { font-size: 1.05rem; }
}

@media (max-width: 700px) {
  .modes { gap: 1rem; }
  .mode-card { min-width: calc(50% - 0.5rem); }
  .result-title { font-size: 2.4rem; }
  .result-shelf { font-size: 1.7rem; }
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
}

.login-panel {
  width: min(100%, 24rem);
  padding: 1.75rem;
  border-radius: 1rem;
  background: var(--bg-idle);
}

.login-panel h1 { margin: 0 0 1.25rem; }

.login-panel form {
  display: grid;
  gap: 0.65rem;
}

.login-panel input,
.login-panel button {
  min-width: 0;
  padding: 0.7rem;
  border: 1px solid var(--muted);
  border-radius: 0.4rem;
  font: inherit;
}

.login-panel input {
  background: var(--input-bg);
  color: var(--text);
}

.login-panel button {
  margin-top: 0.5rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  cursor: pointer;
}

.login-error { margin: 0; color: #ffc0bc; }
