/* NK LABS Warehouse Mode — mobile-first stylesheet */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --accent: #4f8ef7;
  --accent2: #6c63ff;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --text: #e8eaf6;
  --muted: #7b809a;
  --radius: 14px;
  --radius-sm: 8px;
  --nav-h: 68px;
  --top-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px; line-height: 1.5; overscroll-behavior: none;
}

/* ── Layout shells ── */
#wh-app { display: flex; flex-direction: column; height: 100%; }

#wh-topbar {
  height: var(--top-h); min-height: var(--top-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
}
#wh-topbar .back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 20px; padding: 8px; cursor: pointer; border-radius: 50%;
  line-height: 1; display: none;
}
#wh-topbar .back-btn.visible { display: flex; align-items: center; justify-content: center; }
#wh-topbar h1 { font-size: 17px; font-weight: 600; flex: 1; }
#wh-topbar .topbar-right { display: flex; align-items: center; gap: 8px; }
#wh-user-chip {
  font-size: 12px; color: var(--muted); background: var(--surface2);
  padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}

#wh-content {
  flex: 1; overflow-y: auto; padding-bottom: calc(var(--nav-h) + 16px);
  -webkit-overflow-scrolling: touch;
}

#wh-bottomnav {
  height: var(--nav-h); background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.wh-nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 8px 4px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 10px; font-weight: 500;
  transition: color .15s;
}
.wh-nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.wh-nav-btn.active { color: var(--accent); }

/* ── Screens ── */
.wh-screen { display: none; padding: 16px; }
.wh-screen.active { display: block; }

/* ── Cards & tiles ── */
.wh-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.wh-card-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;
}
.wh-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 16px; cursor: pointer;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  transition: border-color .15s, background .15s; min-height: 110px;
  -webkit-user-select: none; user-select: none;
}
.wh-tile:active { background: var(--surface2); border-color: var(--accent); }
.wh-tile .tile-icon { font-size: 30px; line-height: 1; }
.wh-tile .tile-label { font-size: 14px; font-weight: 600; }
.wh-tile .tile-hint { font-size: 11px; color: var(--muted); line-height: 1.3; }

/* ── Buttons ── */
.wh-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 14px 20px; border-radius: var(--radius-sm); border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; line-height: 1;
  transition: opacity .15s; -webkit-user-select: none; user-select: none;
  width: 100%; text-align: center;
}
.wh-btn:active { opacity: .8; }
.wh-btn-primary   { background: var(--accent); color: #fff; }
.wh-btn-success   { background: var(--success); color: #fff; }
.wh-btn-warn      { background: var(--warn); color: #000; }
.wh-btn-danger    { background: var(--danger); color: #fff; }
.wh-btn-ghost     { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.wh-btn-sm { padding: 10px 14px; font-size: 13px; width: auto; border-radius: 6px; }
.wh-btn-row { display: flex; gap: 10px; }
.wh-btn-row .wh-btn { flex: 1; }

/* ── Form elements ── */
.wh-form-group { margin-bottom: 14px; }
.wh-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.wh-input, .wh-select, .wh-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 14px; color: var(--text);
  font-size: 16px; /* 16px prevents iOS zoom */ outline: none;
  transition: border-color .15s; appearance: none; -webkit-appearance: none;
}
.wh-input:focus, .wh-select:focus, .wh-textarea:focus { border-color: var(--accent); }
.wh-textarea { resize: vertical; min-height: 80px; }
.wh-select-wrap { position: relative; }
.wh-select-wrap::after {
  content: '▾'; position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%); pointer-events: none; color: var(--muted);
}

/* ── Status badges ── */
.wh-badge {
  display: inline-block; padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.badge-quarantine { background: #7c3aed22; color: #a78bfa; border: 1px solid #7c3aed44; }
.badge-released   { background: #16a34a22; color: #4ade80; border: 1px solid #16a34a44; }
.badge-hold       { background: #b4520022; color: #fb923c; border: 1px solid #b4520044; }
.badge-expired    { background: #dc262622; color: #f87171; border: 1px solid #dc262644; }
.badge-depleted   { background: #37415122; color: #94a3b8; border: 1px solid #37415144; }
.badge-active     { background: #0e748322; color: #22d3ee; border: 1px solid #0e748344; }
.badge-other      { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

/* ── Section headers ── */
.wh-section-header {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px;
  margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

/* ── Lot detail rows ── */
.wh-detail-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.wh-detail-row:last-child { border-bottom: none; }
.wh-detail-label { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.wh-detail-value { font-size: 14px; text-align: right; max-width: 60%; word-break: break-word; }

/* ── Scanner ── */
#wh-scanner-wrap {
  position: relative; background: #000; border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 1; max-width: 100%; margin: 0 auto 16px;
}
#wh-video { width: 100%; height: 100%; object-fit: cover; display: block; }
#wh-scan-overlay {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; pointer-events: none;
}
.scan-frame {
  width: 65%; aspect-ratio: 1; border: 2px solid var(--accent);
  border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.5);
}
.scan-frame::before, .scan-frame::after {
  content: ''; position: absolute; width: 24px; height: 24px;
  border-color: var(--accent); border-style: solid;
}
#wh-scan-status {
  text-align: center; font-size: 14px; color: var(--muted); margin-bottom: 12px;
}
#wh-scan-result-bar {
  background: var(--success); color: #fff; padding: 12px 16px;
  border-radius: var(--radius-sm); margin-bottom: 12px; display: none;
  font-weight: 600;
}

/* ── Document capture ── */
.doc-thumb-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0;
}
.doc-thumb {
  aspect-ratio: 3/4; background: var(--surface2); border-radius: 8px;
  overflow: hidden; position: relative; border: 1px solid var(--border);
}
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb .remove-btn {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.7);
  border: none; color: #fff; border-radius: 50%; width: 24px; height: 24px;
  font-size: 14px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; line-height: 1;
}
.doc-thumb .page-num {
  position: absolute; bottom: 4px; left: 6px; font-size: 10px;
  color: #fff; background: rgba(0,0,0,.6); padding: 2px 5px; border-radius: 4px;
}

/* ── Photo gallery ── */
.photo-thumb-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0;
}
.photo-thumb {
  aspect-ratio: 1; background: var(--surface2); border-radius: 8px;
  overflow: hidden; position: relative; cursor: pointer;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .photo-cat {
  position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.65);
  font-size: 9px; color: #fff; padding: 3px 5px; text-align: center;
  text-transform: uppercase; letter-spacing: .3px;
}

/* ── Receiving wizard steps ── */
.wh-step-indicator {
  display: flex; gap: 6px; margin-bottom: 20px;
}
.wh-step-dot {
  flex: 1; height: 4px; border-radius: 2px; background: var(--border);
  transition: background .2s;
}
.wh-step-dot.done { background: var(--success); }
.wh-step-dot.active { background: var(--accent); }

/* ── Activity feed ── */
.activity-item {
  display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface2);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  flex-shrink: 0;
}
.activity-body { flex: 1; min-width: 0; }
.activity-action { font-size: 14px; font-weight: 500; }
.activity-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Toast notifications ── */
#wh-toast {
  position: fixed; top: calc(var(--top-h) + 8px); left: 16px; right: 16px;
  z-index: 9000; pointer-events: none;
}
.toast-item {
  margin-bottom: 8px; padding: 14px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.4);
  animation: slideDown .2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warn    { background: var(--warn); color: #000; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Fullscreen photo viewer ── */
#wh-photo-viewer {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.95);
  z-index: 8000; flex-direction: column; align-items: center; justify-content: center;
}
#wh-photo-viewer.open { display: flex; }
#wh-photo-viewer img {
  max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 8px;
}
#wh-photo-viewer-close {
  position: absolute; top: 16px; right: 16px; background: none;
  border: none; color: #fff; font-size: 28px; cursor: pointer; padding: 8px;
}
#wh-photo-viewer-caption {
  color: #ccc; font-size: 13px; margin-top: 12px; text-align: center; padding: 0 20px;
}

/* ── Misc utils ── */
.wh-empty { text-align: center; color: var(--muted); padding: 30px; font-size: 14px; }
.wh-qty-large { font-size: 32px; font-weight: 700; color: var(--text); }
.wh-qty-unit  { font-size: 16px; color: var(--muted); margin-left: 4px; }
.wh-ing-name  { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.wh-lot-num   { font-size: 13px; color: var(--accent); font-family: monospace; }
.wh-divider   { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.wh-row { display: flex; gap: 10px; }
.wh-row > * { flex: 1; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ── Loading spinner ── */
.wh-spinner {
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.wh-spinner::after {
  content: ''; width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
