/* =============================================
   Red Panda Backstock Tracker — Mobile-first
   ============================================= */

:root {
  --red: #c0392b;
  --red-dark: #96281b;
  --orange: #e67e22;
  --green: #27ae60;
  --green-dark: #1e8449;
  --blue: #2980b9;
  --gray-100: #f8f9fa;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-500: #adb5bd;
  --gray-700: #495057;
  --gray-900: #212529;
  --white: #ffffff;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--red);
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 56px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; color: var(--red); margin-bottom: 28px; line-height: 1.3; }

/* ── Forms ── */
.field { text-align: left; margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--gray-300);
  border-radius: 8px;
  font-size: 16px; /* prevents iOS zoom */
  font-family: var(--font);
  color: var(--gray-900);
  background: var(--white);
  transition: border-color 0.15s;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}
.btn:active { opacity: 0.8; }
.btn-block { width: 100%; }
.btn-primary { background: var(--red); color: var(--white); }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-green { background: var(--green); color: var(--white); }
.btn-green:hover { background: var(--green-dark); }
.btn-orange { background: var(--orange); color: var(--white); }
.btn-sm { padding: 8px 14px; font-size: 14px; }

/* ── Error / Success messages ── */
.error-msg { color: var(--red); font-size: 14px; margin-top: 12px; font-weight: 500; }
.success-msg { color: var(--green); font-size: 14px; margin-top: 12px; font-weight: 500; }
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 12px;
}
.alert-error { background: #fde8e8; color: var(--red); }
.alert-success { background: #e8f8ee; color: var(--green-dark); }
.alert-warning { background: #fef3cd; color: #856404; }

/* ── App Shell ── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
  background: var(--red);
  color: var(--white);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.app-header h1 { font-size: 18px; font-weight: 700; }
.app-header .subtitle { font-size: 12px; opacity: 0.8; }
.header-user { font-size: 13px; opacity: 0.9; cursor: pointer; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--gray-500);
  gap: 4px;
  transition: color 0.15s;
}
.nav-btn .icon { font-size: 22px; }
.nav-btn.active { color: var(--red); font-weight: 600; }

/* Main content area — padded above bottom nav */
.page-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 90px;
}

/* ── Scan Box ── */
.scan-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.scan-section h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gray-700); margin-bottom: 10px; }
.scan-input-row {
  display: flex;
  gap: 8px;
}
.scan-input-row input {
  flex: 1;
  font-size: 18px;
  padding: 14px;
  border-width: 2px;
}
.scan-input-row input:focus { border-color: var(--red); }
.scan-btn-camera {
  background: var(--gray-200);
  border: 2px solid var(--gray-300);
  border-radius: 8px;
  padding: 0 14px;
  font-size: 24px;
  cursor: pointer;
}

/* ── Result Cards ── */
.result-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.result-card h3 { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.result-card .sku-label { font-size: 12px; color: var(--gray-500); margin-bottom: 12px; }
.result-card .total-badge {
  display: inline-block;
  background: var(--gray-200);
  color: var(--gray-700);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* Location rows */
.location-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--gray-200);
}
.location-row:first-of-type { border-top: none; }
.location-site-badge {
  background: var(--red);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.location-site-badge.offsite { background: var(--orange); }
.location-details { flex: 1; }
.location-details .box-id { font-size: 15px; font-weight: 700; }
.location-details .shelf { font-size: 13px; color: var(--gray-700); }
.location-qty {
  font-size: 22px;
  font-weight: 700;
  color: var(--green-dark);
  min-width: 36px;
  text-align: right;
}

/* ── Box content list ── */
.box-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--gray-200);
}
.box-item-name { flex: 1; font-size: 15px; font-weight: 500; }
.box-item-sku { font-size: 11px; color: var(--gray-500); }
.box-item-qty {
  font-size: 20px;
  font-weight: 700;
  color: var(--green-dark);
  min-width: 32px;
  text-align: right;
}

/* ── Section headings ── */
.section-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-500);
  margin: 20px 0 8px;
}

/* ── Pill tags ── */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.pill-store { background: #fde8e8; color: var(--red); }
.pill-offsite { background: #fef3cd; color: #856404; }

/* ── Storage run list ── */
.grab-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--gray-200);
  gap: 10px;
}
.grab-row .item-info { flex: 1; }
.grab-row .item-name { font-size: 15px; font-weight: 600; }
.grab-row .item-loc { font-size: 12px; color: var(--gray-500); }
.grab-row .store-qty { font-size: 13px; font-weight: 600; color: var(--red); }

/* ── Modal / Sheet ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: var(--white);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 36px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--gray-300);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-sheet h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* ── Camera scanner overlay ── */
#camera-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 300;
  flex-direction: column;
}
#camera-overlay.open { display: flex; }
#camera-reader {
  width: 100%;
  flex: 1;
}
/* html5-qrcode injects its own video — make it fill the overlay */
#camera-reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}
#camera-reader img { display: none; } /* hide the default scanning icon */
.camera-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 22px;
  cursor: pointer;
}

/* ── Label print area — Zebra ZD411, 1.5" x 1" labels ── */
@media print {
  @page {
    size: 1.5in 1in;
    margin: 0;
  }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .label-item {
    width: 1.5in;
    height: 1in;
    page-break-after: always;
    page-break-inside: avoid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.04in 0.06in;
    box-sizing: border-box;
  }
  .label-item svg { width: 1.32in; height: 0.6in; }
  .label-box-id { font-size: 9pt; font-weight: 700; margin-top: 2px; letter-spacing: 0.02em; }
}
#print-area { display: none; }
.label-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px;
}
.label-item {
  border: 1px dashed #999;
  padding: 8px;
  text-align: center;
  page-break-inside: avoid;
}
.label-item svg { width: 100%; max-width: 160px; }
.label-box-id { font-size: 13px; font-weight: 700; margin-top: 4px; }

/* ── Utility ── */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-small { font-size: 13px; color: var(--gray-500); }
.hidden { display: none !important; }
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tablet/Desktop ── */
@media (min-width: 600px) {
  .page-content { max-width: 560px; margin: 0 auto; }
  .bottom-nav { max-width: 560px; left: 50%; transform: translateX(-50%); }
}
