:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #111827;
  --muted: #5b6472;
  --line: #d7dce3;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --critical: #b42318;
  --critical-bg: #fff0ee;
  --warning: #a15c07;
  --warning-bg: #fff7e6;
  --success: #167c3b;
  --success-bg: #edfdf3;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  background: var(--bg);
}

body {
  height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  height: 100svh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.12;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  line-height: 1.2;
}

.pending-badge {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #e7c36a;
  border-radius: 999px;
  background: var(--warning-bg);
  color: #6d4204;
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.capture-view,
.review-view,
.state-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.capture-view {
  justify-content: center;
  gap: 16px;
  padding-bottom: 12vh;
}

.scanner-label,
.status-text,
.pending-help,
.warning-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.35;
  text-align: center;
}

.capture-button {
  width: 100%;
  min-height: 176px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 1.8rem;
  font-weight: 850;
}

.capture-button:active,
.primary-button:active {
  transform: translateY(1px);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 52px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.compact-button {
  min-height: 48px;
  padding: 0 12px;
}

.primary-button {
  border: 0;
  background: var(--primary);
  color: #fff;
}

.primary-button:hover,
.capture-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  border: 1px solid #f4b5ae;
  background: #fff;
  color: var(--critical);
}

.review-view {
  gap: 8px;
}

.preview-frame {
  flex: 1 1 auto;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  overflow: hidden;
}

.preview-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center center;
}

.review-form {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 8px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-row label {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.field-row label span {
  color: var(--muted);
  font-weight: 600;
}

.field-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-size: 1rem;
}

.field-row input:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.warning-text {
  padding: 10px 12px;
  border: 1px solid #f4d08a;
  border-radius: 8px;
  background: var(--warning-bg);
  color: var(--warning);
  text-align: left;
}

.action-row {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: 0.9fr 1.3fr;
  gap: 10px;
  padding-top: 2px;
  background: var(--bg);
}

.state-card {
  justify-content: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
  text-align: center;
}

.state-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.state-card.critical {
  border-color: #f4b5ae;
  background: var(--critical-bg);
}

.state-card.critical h2 {
  color: var(--critical);
}

.state-card.success {
  border-color: #a7efc2;
  background: var(--success-bg);
}

.state-card.success h2 {
  color: var(--success);
}

.state-card.warning {
  border-color: #f4d08a;
  background: var(--warning-bg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.queue-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.48);
}

.queue-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 560px);
  max-height: 78svh;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 8px 8px 0 0;
  background: #fff;
  box-shadow: var(--shadow);
  transform: translate(-50%, 110%);
  transition: transform 160ms ease;
}

.queue-panel.open {
  transform: translate(-50%, 0);
}

.queue-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.queue-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
}

.queue-list {
  display: flex;
  max-height: calc(78svh - 100px);
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.queue-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.queue-time,
.queue-status,
.queue-error {
  margin: 0;
  line-height: 1.35;
}

.queue-time {
  color: var(--text);
  font-weight: 800;
}

.queue-status {
  color: var(--muted);
}

.queue-error {
  margin-top: 4px;
  color: var(--critical);
  font-size: 0.92rem;
}

.queue-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-height: 660px) {
  .app-shell {
    gap: 8px;
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  h1 {
    font-size: 1.35rem;
  }

  .capture-view {
    padding-bottom: 2vh;
  }

  .capture-button {
    min-height: 132px;
    font-size: 1.45rem;
  }

  .preview-frame {
    min-height: 120px;
  }

  .field-row input,
  .primary-button,
  .secondary-button,
  .danger-button {
    min-height: 42px;
  }
}

@media (min-width: 700px) {
  .app-shell {
    justify-content: center;
    padding-top: 28px;
    padding-bottom: 28px;
  }
}
