:root {
  --color-primary: #171717;
  --color-on-primary: #ffffff;
  --color-secondary: #404040;
  --color-accent: #a16207;
  --color-on-accent: #ffffff;
  --color-background: #ffffff;
  --color-surface: #ffffff;
  --color-foreground: #171717;
  --color-muted: #f2f2f3;
  --color-muted-foreground: #6b6b6f;
  --color-border: #e5e5e5;
  --color-success: #15803d;
  --color-success-bg: #dcfce7;
  --color-destructive: #dc2626;
  --color-destructive-bg: #fee2e2;
  --color-ring: #171717;
  --radius: 12px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #f2f2f3;
    --color-on-primary: #171717;
    --color-secondary: #d4d4d8;
    --color-accent: #eab308;
    --color-on-accent: #171717;
    --color-background: #121212;
    --color-surface: #1c1c1e;
    --color-foreground: #f2f2f3;
    --color-muted: #262628;
    --color-muted-foreground: #a1a1aa;
    --color-border: #333336;
    --color-success: #4ade80;
    --color-success-bg: #14532d;
    --color-destructive: #f87171;
    --color-destructive-bg: #450a0a;
    --color-ring: #f2f2f3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--color-background);
  color: var(--color-foreground);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.topbar {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 700;
  letter-spacing: -0.01em;
  position: sticky; top: 0; z-index: 10;
  background: var(--color-background);
}
.topbar .logo-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--color-primary); color: var(--color-on-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 900; flex-shrink: 0;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  min-height: calc(100vh - 61px);
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }

h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 var(--space-1); }
p.hint { color: var(--color-muted-foreground); margin: 0 0 var(--space-5); }

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: var(--space-2); }

input[type="text"], input[type="number"], input[type="file"] {
  width: 100%;
  font-size: 1rem;
  padding: 13px 14px;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  background: var(--color-surface);
  color: var(--color-foreground);
}
input:focus { border-color: var(--color-ring); }

button {
  font-size: 1rem;
  font-weight: 600;
  padding: 14px;
  min-height: 44px;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: var(--color-on-primary);
  cursor: pointer;
  width: 100%;
  transition: opacity 150ms ease-out, transform 150ms ease-out;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
}
button:hover { opacity: 0.88; }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.accent { background: var(--color-accent); color: var(--color-on-accent); }
button.secondary { background: var(--color-muted); color: var(--color-foreground); }
button.danger { background: var(--color-destructive); color: #fff; }
button.small { width: auto; padding: 8px 12px; min-height: 36px; font-size: 0.85rem; }

#reader { width: 100%; border-radius: var(--radius); overflow: hidden; margin-bottom: var(--space-3); border: 1px solid var(--color-border); }
#reader video { width: 100%; height: 200px; object-fit: cover; display: block; }

.indicator {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius);
  font-weight: 600;
  margin-bottom: var(--space-3);
  min-height: 24px;
  transition: background 150ms ease-out;
}
.indicator.success { background: var(--color-success-bg); color: var(--color-success); }
.indicator.fail { background: var(--color-destructive-bg); color: var(--color-destructive); }
.indicator.idle { background: transparent; color: var(--color-muted-foreground); }
.indicator svg { flex-shrink: 0; }

.item-list { list-style: none; padding: 0; margin: 0 0 var(--space-3); flex: 1; overflow-y: auto; }
.item-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border);
  font-variant-numeric: tabular-nums;
}
.item-list li .price { color: var(--color-muted-foreground); }
.item-list li .item-name { flex: 1; }
.item-list li .qty { color: var(--color-muted-foreground); font-size: 0.85rem; }
.qty-controls { display: flex; align-items: center; gap: var(--space-2); margin-right: var(--space-3); }
.qty-btn {
  width: 40px; height: 40px; min-height: 40px; padding: 0;
  font-size: 1.2rem; border-radius: 8px;
  background: var(--color-muted); color: var(--color-foreground);
}
.qty-num { min-width: 20px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.item-list .empty { padding: var(--space-5) 0; text-align: center; color: var(--color-muted-foreground); }

.total-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 1.3rem; font-weight: 800;
  padding: var(--space-4) 0; border-top: 2px solid var(--color-primary); margin-bottom: var(--space-4);
  font-variant-numeric: tabular-nums;
}
.total-row span:first-child { font-size: 0.95rem; font-weight: 600; color: var(--color-muted-foreground); }

.qr-box { text-align: center; margin-bottom: var(--space-5); }
.qr-box img { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--color-border); }
.qr-box .placeholder {
  padding: var(--space-7) var(--space-4); border: 1px dashed var(--color-border);
  border-radius: var(--radius); color: var(--color-muted-foreground);
}

.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: var(--space-4); margin-bottom: var(--space-4);
}

table { width: 100%; border-collapse: collapse; margin-bottom: var(--space-5); }
th, td { text-align: left; padding: var(--space-2) var(--space-1); border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
th { color: var(--color-muted-foreground); font-weight: 600; }
td.price { font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: var(--space-2); }

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; gap: var(--space-2); }
.row > * { flex: 1; margin-bottom: 0; }

.section-title { font-size: 1.05rem; font-weight: 700; margin: var(--space-6) 0 var(--space-3); }
.section-title:first-child { margin-top: 0; }

#scan-box video { width: 100%; height: 200px; object-fit: cover; display: block; border-radius: var(--radius); border: 1px solid var(--color-border); }

.detail-row td { background: var(--color-muted); }
.detail-line { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--color-primary); color: var(--color-on-primary);
  padding: 12px 18px; border-radius: var(--radius); font-weight: 600; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 200ms ease-out;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.visible { opacity: 1; }
