:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1b1f1a;
  --muted: #6b7268;
  --border: #e2e5df;
  --green: #2e7d4f;
  --green-dark: #235f3c;
  --red: #b3473a;
  --red-dark: #8f3a30;
  --accent-bg: #eef6f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1e2423;
    --text: #e8ece8;
    --muted: #93998f;
    --border: #2d3431;
    --green: #4caf7d;
    --green-dark: #3d9067;
    --red: #e07a6c;
    --red-dark: #c05f52;
    --accent-bg: #1a2a22;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.status-pill {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--muted);
}
.status-pill.online { color: var(--green-dark); }
.status-pill.error { color: var(--red-dark); }

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: none;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--green);
  font-weight: 600;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

#reader {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  min-height: 0;
}

.scan-actions {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.camera-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.camera-pick select {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.primary-btn, .secondary-btn, .danger-btn {
  padding: 12px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

.primary-btn {
  background: var(--green);
  border-color: var(--green);
  color: white;
  flex: 1;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  flex: 1;
}

.danger-btn {
  background: var(--red);
  border-color: var(--red);
  color: white;
  flex: 1;
}

.primary-btn:disabled, .danger-btn:disabled { opacity: 0.45; cursor: default; }

.feedback {
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 1rem;
  color: var(--muted);
}

.feedback.success, .feedback.error { font-weight: 600; }
.feedback.success { background: var(--accent-bg); color: var(--green-dark); border-color: var(--green); }
.feedback.error { background: #fbeceb; color: var(--red-dark); border-color: var(--red); }

@media (prefers-color-scheme: dark) {
  .feedback.error { background: #2a1917; }
}

.inventory-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.inventory-toolbar input {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

.inventory-toolbar .quick-add-btn { flex: 0 0 auto; }

.inventory-feedback { margin-bottom: 14px; }

.inventory-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inventory-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.inventory-item img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--accent-bg);
  flex-shrink: 0;
}

.inventory-item .item-info {
  flex: 1;
  min-width: 0;
}

.inventory-item .item-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inventory-item .item-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-controls button {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--accent-bg);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.qty-value {
  min-width: 22px;
  text-align: center;
  font-weight: 700;
}

.qty-value.zero { color: var(--red); }

.item-delete {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  max-width: 320px;
  width: 90%;
}

dialog::backdrop {
  background: rgba(0,0,0,0.4);
}

dialog h3 { margin-top: 0; }

dialog label {
  display: block;
  margin: 12px 0;
  font-size: 0.9rem;
}

dialog input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.dialog-actions + .dialog-actions { margin-top: 10px; }

.scan-item {
  display: flex;
  gap: 12px;
  align-items: center;
}

.scan-item img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  flex-shrink: 0;
}

.scan-item-text { min-width: 0; }
.scan-item h3 { margin: 0 0 4px; font-size: 1.2rem; }
#scan-meta { font-size: 0.85rem; overflow-wrap: anywhere; }

.scan-stock {
  margin: 14px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
}
