:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-light: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;
  --border: #334155;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 18px;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

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

header.topbar h1 {
  font-size: 20px;
  margin: 0;
}

header.topbar .who {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: var(--muted);
}

a, button {
  font-family: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  padding: 14px 18px;
}

.btn-primary {
  background: var(--accent);
  color: #06210f;
}
.btn-primary:active { background: var(--accent-dark); }

.btn-secondary {
  background: var(--panel-light);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-link {
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  font-weight: 500;
  font-size: 15px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-block { width: 100%; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 16px;
  font-size: 20px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--panel);
  color: var(--text);
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.scan-box {
  margin: 18px 0;
  position: relative;
}
.scan-box label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 15px;
}

.scan-row {
  display: flex;
  gap: 8px;
}
.scan-row input { flex: 1; min-width: 0; }
.btn-icon {
  padding: 14px 16px;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 20;
  max-height: 340px;
  overflow-y: auto;
  box-shadow: 0 10px 30px #0008;
}
.suggestion-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active,
.suggestion-item:hover {
  background: var(--panel-light);
}
.suggestion-item img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: #0009;
  flex-shrink: 0;
}
.suggestion-item .s-meta { min-width: 0; }
.suggestion-item .s-title {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggestion-item .s-sub {
  font-size: 13px;
  color: var(--muted);
}

.camera-modal {
  position: fixed;
  inset: 0;
  background: #000c;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.camera-modal-inner {
  width: 100%;
  max-width: 520px;
  /* Cap total height to the viewport (minus the modal's own 16px top/bottom
     padding) and lay out as a column, so the video area shrinks to fit
     rather than pushing the hint/status text and Capture/Cancel buttons
     below the screen. Without this, a tall video stream (some cameras
     report portrait-oriented dimensions) could grow past the viewport
     with no way to reach the controls at all. */
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.camera-video-wrap {
  position: relative;
  width: 100%;
  /* Grows to fill whatever space is left after the hint/status/controls
     below take their fixed height, but can also shrink below the video's
     natural content size (min-height: 0 is required for that in a flex
     column - the default min-height:auto would otherwise stop it). */
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
#camera-video {
  width: 100%;
  height: 100%;
  display: block;
  /* Fills the (now height-constrained) video-wrap by cropping rather than
     letting its native aspect ratio dictate the layout height. */
  object-fit: cover;
}
.camera-guide {
  /* Kept in sync with the crop percentages in captureAndRead() in app.js
     (15%/15%/42%/16%) - narrowed from the original box so SKU mode is less
     likely to pick up nearby label text like "ITEM #:". */
  position: absolute;
  left: 15%;
  right: 15%;
  top: 42%;
  height: 16%;
  border: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.camera-hint {
  color: var(--text);
  text-align: center;
  font-size: 15px;
  margin: 14px 0 4px;
  flex-shrink: 0;
}
.camera-status {
  color: var(--accent);
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  margin: 0 0 10px;
  flex-shrink: 0;
}
.camera-controls {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.camera-controls button { flex: 1; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.product-header {
  display: flex;
  gap: 14px;
  align-items: center;
}
.product-header img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  background: #0009;
  flex-shrink: 0;
}
.product-header .meta { min-width: 0; }
.product-header h2 {
  margin: 0 0 4px 0;
  font-size: 19px;
  line-height: 1.25;
}
.product-header .sub {
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn);
  color: #241a00;
  margin-left: 6px;
  vertical-align: middle;
}

table.qty-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}
table.qty-table th, table.qty-table td {
  text-align: left;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
table.qty-table th {
  color: var(--muted);
  font-weight: 500;
}
table.qty-table td.qty {
  font-size: 18px;
  font-weight: 700;
  text-align: right;
}
table.qty-table tr.zero td.qty { color: var(--muted); }
table.qty-table tr.total td { border-top: 2px solid var(--border); border-bottom: none; font-weight: 700; }

.loc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.loc-row:last-child { border-bottom: none; }
.loc-row .label {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 4px;
}
.loc-row .value {
  font-size: 20px;
  font-weight: 600;
  word-break: break-word;
}
.loc-row .value.empty {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

.edit-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.edit-row input { width: 100%; }
.edit-actions {
  display: flex;
  gap: 8px;
}
.edit-actions .btn-primary,
.edit-actions .btn-secondary:not(.btn-icon) {
  flex: 1;
}

.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #06210f;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  box-shadow: 0 6px 20px #0006;
  z-index: 50;
}
.toast.error { background: var(--danger); color: #fff; }

.error-box {
  background: #3b0f14;
  border: 1px solid var(--danger);
  color: #fecaca;
  padding: 12px 14px;
  border-radius: var(--radius);
  margin: 12px 0;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}

.login-wrap {
  max-width: 380px;
  margin: 12vh auto 0;
  padding: 24px;
}
.login-wrap h1 {
  text-align: center;
  margin-bottom: 24px;
}
.login-wrap .field { margin-bottom: 14px; }
.login-wrap label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 14px; }

table.staff-table, table.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.staff-table th, table.staff-table td,
table.audit-table th, table.audit-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
