:root {
  --bg: #ffffff;
  --text: #111111;
  --dim: #767676;
  --border: #e6e6e6;
  --surface: #f4f4f4;
  --accent: #111111;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The hidden attribute must beat our display rules on overlays */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; color: inherit; }
input { font: inherit; color: inherit; }

/* ---------- Password gate ---------- */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lock-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.lock-form h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lock-hint {
  margin: 0 0 8px;
  color: var(--dim);
  font-size: 14px;
}

.lock-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px;
  text-align: center;
}

.lock-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 0;
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--dim);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.search-input {
  width: 100%;
  margin: 12px 0 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px; /* prevents iOS zoom on focus */
}

.search-input::placeholder { color: var(--dim); }

.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 12px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--dim);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ---------- Item list ---------- */
.item-list {
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px);
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.empty-state {
  text-align: center;
  color: var(--dim);
  padding: 64px 24px;
  font-size: 14px;
  line-height: 1.6;
}

.item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.item-thumb {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--dim);
  overflow: hidden;
}

.item-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--surface);
}

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

.item-name {
  font-weight: 500;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  font-size: 12px;
  color: var(--dim);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loc-badge {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  margin-right: 8px;
}

.qty-stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.qty-stepper button {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
}

.qty-stepper button:active { opacity: 0.5; }

.qty-stepper output {
  min-width: 26px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.restock-btn {
  border: 1px solid var(--accent);
  background: none;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 500;
  font-size: 13px;
}

/* ---------- Tab bar ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
}

.tab {
  border: none;
  background: none;
  color: var(--dim);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  position: relative;
}

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

.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  padding: 0 4px;
}

.scan-fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -24px;
}

.scan-fab:active { opacity: 0.8; }

/* ---------- Scanner ---------- */
.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.scanner-viewport {
  position: relative;
  width: 100%;
  flex: 1;
  overflow: hidden;
}

.scanner-viewport video,
.scanner-viewport #scanner-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(80vw, 360px);
  height: 160px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.scanner-status {
  color: #fff;
  margin: 0;
  font-size: 14px;
  text-align: center;
  padding: 0 24px;
}

.scanner-close {
  margin-bottom: calc(env(safe-area-inset-bottom) + 20px);
}

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
}

.sheet {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: slide-up 0.2s ease-out;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 6px auto 16px;
}

.sheet-product {
  display: flex;
  gap: 12px;
  align-items: center;
}

.sheet-product img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--surface);
}

.sheet-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-fields input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px;
}

.sheet-locations { margin: 16px 0 4px; padding-bottom: 4px; }

.sheet-qty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 18px;
  font-weight: 500;
  font-size: 15px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  flex: 1;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
}

.btn-primary:disabled { opacity: 0.5; }

.btn-secondary {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: none;
  color: #fff;
  border-radius: var(--radius);
  padding: 11px 32px;
  font-size: 14px;
  font-weight: 500;
}

.btn-danger {
  border: 1px solid var(--border);
  background: none;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 13px 18px;
  font-weight: 600;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --text: #f2f2f2;
    --dim: #969696;
    --border: #2c2c2c;
    --surface: #222222;
    --accent: #f2f2f2;
    --accent-text: #141414;
    --danger: #e57373;
  }
}
