:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --ink: #14211f;
  --muted: #667470;
  --line: #d9e2df;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #d9f1ec;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 14px 35px rgba(15, 23, 42, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  background: var(--bg);
  padding: max(14px, env(safe-area-inset-top)) 14px max(104px, calc(env(safe-area-inset-bottom) + 104px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.55rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.scanner-panel,
.list-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.05);
}

.scanner-panel {
  padding: 10px;
}

.scanner-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0f1a18;
  border: 1px solid #0c2f2b;
}

.scanner-frame::before,
.scanner-frame::after {
  position: absolute;
  inset: 16%;
  pointer-events: none;
  content: "";
}

.scanner-frame::before {
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 6px;
}

.scanner-frame::after {
  border: 1px solid rgba(15, 118, 110, 0.88);
  transform: translate(8px, 8px);
}

#scannerVideo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 8px;
  align-content: center;
  color: #e7efed;
  text-align: center;
  background: #12201d;
}

.scanner-empty svg {
  width: 42px;
  height: 42px;
}

.scanner-empty.hidden {
  display: none;
}

.scan-line {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 49%;
  height: 2px;
  background: #34d399;
  box-shadow: 0 0 16px rgba(52, 211, 153, 0.8);
  transform: translateY(-50%);
  opacity: 0.92;
}

.scanner-actions,
.manual-row,
.section-head,
.dialog-head,
.dialog-actions,
.quantity-row {
  display: flex;
  align-items: center;
}

.scanner-actions {
  gap: 9px;
  margin-top: 10px;
}

.scan-status {
  min-height: 20px;
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 680;
  line-height: 1.35;
}

.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;
}

.primary-button,
.secondary-button,
.text-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 760;
}

.primary-button,
.secondary-button {
  flex: 1 1 auto;
  padding: 0 14px;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
}

.primary-button:active {
  background: var(--primary-dark);
}

.secondary-button {
  color: var(--ink);
  background: #e7eeeb;
}

.text-button {
  color: var(--primary-dark);
  background: var(--primary-soft);
  padding: 0 12px;
}

.icon-button {
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: #e7eeeb;
  flex: 0 0 44px;
}

.icon-button.strong {
  color: #ffffff;
  background: var(--primary);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.3;
}

.manual-form {
  margin-top: 12px;
}

.manual-form label,
.quantity-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 720;
}

.manual-row {
  gap: 8px;
}

input {
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.metric {
  min-height: 68px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  line-height: 1.2;
  word-break: break-word;
}

.metric.wide strong {
  font-size: 0.95rem;
}

.list-section {
  padding: 10px;
}

.section-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.empty-list {
  min-height: 118px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-list.hidden {
  display: none;
}

.empty-list svg {
  width: 32px;
  height: 32px;
}

.count-list {
  display: grid;
  gap: 8px;
}

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

.count-main {
  min-width: 0;
}

.barcode {
  display: block;
  margin-bottom: 4px;
  font-size: 1rem;
  font-weight: 780;
  line-height: 1.2;
  word-break: break-all;
}

.product-meta {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.price-meta {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 760;
  line-height: 1.35;
}

.qty-pill {
  min-width: 58px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: var(--radius);
  font-weight: 820;
}

.row-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.row-actions button {
  min-height: 36px;
  flex: 1 1 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #ffffff;
  font-weight: 720;
}

.row-actions button:last-child {
  color: var(--danger);
}

.quantity-dialog {
  width: min(calc(100% - 24px), 480px);
  max-height: calc(100svh - 24px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.quantity-dialog::backdrop {
  background: rgba(8, 21, 19, 0.58);
}

.quantity-card {
  padding: 14px;
  background: #ffffff;
}

.dialog-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.dialog-head h2 {
  max-width: 320px;
  word-break: break-all;
}

.product-box {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  padding: 12px;
  background: #f5f8f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.product-box.warning {
  background: #fff7ed;
  border-color: #fed7aa;
}

.product-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.product-line strong {
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}

.quantity-row {
  gap: 8px;
}

.quantity-row input {
  height: 56px;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 820;
}

.stepper {
  width: 56px;
  height: 56px;
  flex-basis: 56px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.quick-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #ffffff;
  font-weight: 780;
}

.dialog-actions {
  gap: 9px;
  padding: 0;
  margin: 14px 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 88px));
  z-index: 20;
  max-width: min(420px, calc(100% - 28px));
  padding: 11px 14px;
  color: #ffffff;
  background: #13201d;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translate(-50%, 120%);
  opacity: 0;
  transition: transform 160ms ease, opacity 160ms ease;
  font-weight: 700;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.bottom-scan-button {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 19;
  width: min(340px, calc(100% - 34px));
  min-height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.28);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 820;
  transform: translateX(-50%);
}

.bottom-scan-button:disabled {
  opacity: 0.62;
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 960px);
  }

  main {
    display: grid;
    grid-template-columns: minmax(330px, 420px) 1fr;
    gap: 12px;
    align-items: start;
  }

  .status-grid {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, 1fr);
    order: -1;
    margin-top: 0;
  }

  .metric.wide {
    grid-column: auto;
  }

  .list-section {
    min-height: 100%;
  }
}
