:root {
  --bg: #0b1221;
  --surface: #141c2f;
  --surface-2: #1c2740;
  --border: #26314f;
  --text: #e8edf7;
  --muted: #8a97b5;
  --primary: #3b82f6;
  --primary-press: #2f6fe0;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

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

body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); margin: 10px 0 0; font-size: 14px; }

/* Screens */
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Fixed, non-scrolling screens (scan + details). Fills the viewport exactly
   so the camera and footer stay put no matter how many items are scanned. */
.screen-fixed {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 20px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }

.login-card { margin-top: 8vh; }

.brand { text-align: center; margin-bottom: 18px; }
.brand-logo { font-size: 44px; }
.brand h1 { margin: 6px 0 2px; font-size: 24px; letter-spacing: 0.5px; }
.brand .muted { margin: 0; font-size: 14px; }

/* Form fields */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input,
.field select {
  width: 100%;
  padding: 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  appearance: none;
}
.field input:focus,
.field select:focus { border-color: var(--primary); }
.field select { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a97b5' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 14px center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-press); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
  align-self: center;
}

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.resume { border-color: var(--warn); }

/* Banner */
.banner {
  position: sticky;
  top: 0;
  z-index: 50;
  text-align: center;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
}
.banner.offline { background: var(--warn); color: #1a1206; }
.banner.syncing { background: var(--primary); color: #fff; }
.banner.error { background: var(--danger); color: #fff; }

/* Scan header */
.scan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.scan-meta { display: flex; flex-direction: column; gap: 4px; }
.scan-meta strong { font-size: 16px; }
.pill {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  width: fit-content;
}
.scan-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 13px; color: var(--muted); }
.scan-totals b { color: var(--text); font-size: 17px; }

/* "View details" button in the scan header */
.details-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--text);
  cursor: pointer;
}
.details-btn:active { transform: scale(0.98); }
.details-counts { font-size: 13px; color: var(--muted); }
.details-counts b { color: var(--text); font-size: 15px; }
.details-cta { font-size: 13px; font-weight: 600; color: var(--primary); }

/* Round back / icon button */
.icon-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

/* Camera reader — kept compact so it doesn't dominate the screen. */
.reader {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  height: 360px;
  max-height: 55vh;
}
.reader video { width: 100% !important; height: 100% !important; object-fit: cover; display: block; }
#reader__scan_region img { display: none; } /* hide default info image */

/* Scan confirmation card (overlays the reader) */
/* On the fixed scan screen, the reader area grows to fill the gap between
   the header and the controls so nothing overflows / scrolls. */
/* Compact camera: the wrap sizes to the reader, not the whole screen. */
.reader-wrap { position: relative; flex: 0 0 auto; }
.screen-fixed .scan-controls { flex: 0 0 auto; }
/* The last-scan toast area takes the leftover space on the scan screen. */
#screen-scan .last-scan { flex: 0 0 auto; }
/* The confirm card expands downward from the top of the camera area so it has
   room even though the camera itself is compact. */
.confirm-card {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  min-height: 100%;
  background: var(--surface);
  border: 2px solid var(--success);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 18px;
  z-index: 10;
  animation: pop 0.18s ease;
}
.confirm-label { margin: 0; text-align: center; color: var(--success); font-weight: 700; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; }
.confirm-sku {
  margin: 0;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  font-weight: 700;
  word-break: break-all;
  line-height: 1.3;
  /* Keep long values (e.g. a URL from a QR code) from dominating the card. */
  max-height: 3.9em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.confirm-qty { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.confirm-qty-label { font-size: 13px; color: var(--muted); }
.confirm-qty-input {
  width: 72px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  padding: 10px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.confirm-qty-input:focus { border-color: var(--primary); }
.confirm-actions { margin-top: 4px; }

.scan-controls { display: flex; gap: 10px; }
.scan-controls .btn { flex: 1; padding: 12px; font-size: 14px; }

/* Last scan toast */
.last-scan {
  background: var(--surface-2);
  border: 1px solid var(--success);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  animation: pop 0.25s ease;
}
.last-scan b { color: var(--success); }
@keyframes pop { from { transform: scale(0.96); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

/* Line list */
.line-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
/* On the details screen the list scrolls on its own; header + footer stay put. */
.details-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px; }
.line-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.line-item.flash { border-color: var(--success); }
.line-sku { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; word-break: break-all; }
.qty-controls { display: flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.qty-val { min-width: 34px; text-align: center; font-size: 17px; font-weight: 700; }
.qty-val.editable { text-decoration: underline dotted; cursor: pointer; }
.line-del { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 6px; }

/* Scan footer */
.scan-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }

/* Done */
.done-check {
  width: 72px; height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 40px;
  display: flex; align-items: center; justify-content: center;
}

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal-box {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0 0 14px; }
.modal-box input {
  width: 100%; padding: 14px; font-size: 18px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.modal-actions { margin-top: 16px; }

/* Admin specifics */
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted); font-weight: 600; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 0 0 14px; }
.section-title h2 { margin: 0; font-size: 18px; }
.inline-form { display: flex; gap: 10px; }
.inline-form .admin-input { flex: 1; }

/* Dark text inputs used across the admin panel (fixes the white boxes).
   Applied directly to <input> elements, unlike .field which targets a child. */
.admin-input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  appearance: none;
}
.admin-input::placeholder { color: var(--muted); }
.admin-input:focus { border-color: var(--primary); }

/* Scan types list rows */
.type-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.type-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px 8px 12px;
}
.type-row .admin-input { background: var(--surface); }
.type-del {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.type-del:hover { background: rgba(239, 68, 68, 0.12); color: var(--danger); border-color: var(--danger); }
.type-del:active { transform: scale(0.95); }

/* ===================================================================
   Desktop admin layout (scoped to body.admin so the scanner is untouched)
   =================================================================== */

/* The admin login card stays centered and narrow like the scanner. The
   dashboard, however, uses the full width. */
body.admin .admin-shell {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* Top bar */
body.admin .admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
body.admin .admin-brand { display: flex; align-items: center; gap: 12px; }
body.admin .admin-logo { font-size: 26px; }
body.admin .admin-brand strong { display: block; font-size: 17px; }
body.admin .admin-subtitle { font-size: 13px; }

/* Responsive grid: two columns on desktop, one on narrow screens. */
body.admin .admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
body.admin .admin-col-span-2 { grid-column: 1 / -1; }
body.admin .admin-grid .card { height: 100%; margin: 0; }

/* Tables get horizontal scroll safety on smaller widths. */
body.admin .table-wrap { width: 100%; overflow-x: auto; }
body.admin .admin-table { min-width: 520px; }
body.admin .admin-table th,
body.admin .admin-table td { padding: 12px 10px; }
body.admin .admin-table tbody tr:hover { background: var(--surface-2); }

/* Order upload laid out in a row on desktop. */
body.admin .order-upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr auto;
  gap: 12px;
  align-items: end;
}
body.admin .order-upload-row .field { margin-bottom: 0; }
body.admin .order-upload-row .btn { height: 48px; white-space: nowrap; }

/* Wider modal for reconciliation / detail on desktop. */
body.admin .modal-box { max-width: 720px !important; width: 100%; }

/* Collapse to a single column on tablets / phones. */
@media (max-width: 820px) {
  body.admin .admin-grid { grid-template-columns: 1fr; }
  body.admin .order-upload-row { grid-template-columns: 1fr; }
  body.admin .admin-shell { padding: 14px; }
}
