:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-strong: #eef7f3;
  --text: #17201d;
  --muted: #5f6f69;
  --border: #d9e3df;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(23, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0 18px;
}

.store-label {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.85rem;
  line-height: 1.05;
  font-weight: 800;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.mode-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-dark);
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.scanner-region,
.product-region,
.cart-region,
.receipt-region {
  margin-bottom: 16px;
}

.scanner-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #16211f;
  box-shadow: var(--shadow);
}

#cameraPreview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  color: #d7f5ed;
  text-align: center;
}

.scanner-empty strong {
  font-size: 1rem;
}

.scanner-empty span {
  color: #9acbc0;
  font-size: 0.85rem;
}

.scan-reticle {
  position: absolute;
  inset: 22%;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.22);
}

.scanner-actions {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px;
  margin-top: 10px;
}

.primary,
.checkout-button {
  min-height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 800;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.manual-form,
.checkout-form {
  display: grid;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.manual-form div {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
}

input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.manual-form button,
.sample-strip button,
.quantity-controls button {
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  font-weight: 800;
}

.sample-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.sample-strip button {
  min-height: 40px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.section-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.empty-panel,
.product-card,
.cart-line,
.totals,
.checkout-form,
.receipt-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.empty-panel {
  padding: 18px;
  color: var(--muted);
  font-size: 0.94rem;
}

.product-card {
  padding: 14px;
}

.product-main {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.product-main h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.product-main p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.price-stack {
  flex: 0 0 auto;
  text-align: right;
}

.price-stack strong {
  display: block;
  font-size: 1rem;
}

.price-stack span {
  color: var(--warning);
  font-size: 0.78rem;
  font-weight: 800;
}

.product-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.product-meta > div {
  min-width: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 9px;
}

.product-meta > div > span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.product-meta > div > strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
}

.product-meta > div > small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.product-meta.compact {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 10px;
}

.inventory-breakdown {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.inventory-breakdown div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.inventory-breakdown span,
.inventory-breakdown strong {
  overflow-wrap: anywhere;
  font-size: 0.72rem;
}

.inventory-breakdown span {
  color: var(--muted);
  font-weight: 700;
}

.inventory-breakdown strong {
  color: var(--text);
  font-weight: 800;
  text-align: right;
}

.attributes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.attributes span {
  border-radius: 999px;
  background: #edf2f7;
  color: #334155;
  padding: 6px 9px;
  font-size: 0.76rem;
  font-weight: 700;
}

.attributes.empty span {
  color: var(--muted);
}

.cart-lines {
  display: grid;
  gap: 8px;
}

.cart-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
}

.cart-line.selectable {
  cursor: pointer;
}

.cart-line.selectable:hover {
  border-color: var(--accent);
}

.cart-line.selectable:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
  outline: none;
}

.cart-line h3 {
  margin: 0 0 3px;
  font-size: 0.95rem;
}

.cart-line p {
  color: var(--muted);
  font-size: 0.8rem;
}

.line-total {
  text-align: right;
  font-size: 0.92rem;
  font-weight: 800;
}

.cart-line-details {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.cart-line-details p {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.quantity-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 38px 52px 38px 1fr;
  gap: 8px;
  align-items: center;
}

.quantity-controls button {
  width: 38px;
  height: 36px;
  font-size: 1rem;
}

.quantity-controls output {
  text-align: center;
  font-weight: 800;
}

.quantity-controls .remove {
  width: auto;
  justify-self: end;
  color: var(--danger);
  padding: 0 12px;
}

.totals {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.totals strong {
  color: var(--text);
}

.totals .grand-total {
  border-top: 1px solid var(--border);
  color: var(--text);
  padding-top: 10px;
  font-size: 1.05rem;
  font-weight: 800;
}

.checkout-form {
  margin-top: 10px;
  padding: 12px;
}

.receipt-panel {
  padding: 14px;
}

.receipt-panel strong {
  display: block;
  font-size: 1.2rem;
}

.receipt-panel span {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  transform: translate(-50%, 120%);
  width: min(92vw, 480px);
  max-height: min(70vh, 520px);
  border-radius: 8px;
  background: #17201d;
  color: #fff;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  transition: transform 180ms ease;
}

.toast.visible {
  transform: translate(-50%, 0);
}

.toast.error {
  background: #7f1d1d;
}

.toast pre {
  min-width: 0;
  max-height: calc(min(70vh, 520px) - 24px);
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: inherit;
  font: inherit;
  font-weight: 700;
  line-height: 1.35;
}

.toast-actions {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.toast.actionable .toast-actions {
  display: flex;
}

.toast-actions button {
  min-width: 76px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

@media (max-width: 430px) {
  .scanner-actions {
    grid-template-columns: 1fr;
  }

  .product-meta {
    grid-template-columns: 1fr;
  }

  .product-meta.compact {
    grid-template-columns: 1fr;
  }

  .toast {
    width: calc(100vw - 20px);
    grid-template-columns: 1fr;
  }

  .toast-actions {
    flex-direction: row;
    justify-self: end;
  }
}
