:root {
  --navy-deep: #000e28;
  --navy: #072130;
  --navy-soft: #0f3d57;
  --orange: #f37321;
  --orange-soft: #fde8d9;
  --bg: #f3f9ff;
  --ink: #212529;
  --ink-muted: #6a7177;
  --line: #d7dadb;
  --white: #ffffff;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(0, 14, 40, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--navy);
  color: var(--white);
  padding: 14px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
}

.brand-sub {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-wrap input {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--navy-soft);
  background: var(--navy-deep);
  color: var(--white);
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 230px;
}

.search-wrap input::placeholder {
  color: #9fb3c0;
}

.search-wrap input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
}

.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 20px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-outline {
  background: transparent;
  color: var(--white);
  border: 1px solid var(--white);
}

.btn-outline:hover {
  background: var(--white);
  color: var(--navy-deep);
}

.btn-orange {
  background: var(--orange);
  color: var(--white);
}

.btn-orange:hover {
  background: #d9620f;
}

.btn-danger {
  background: transparent;
  color: #b42318;
  border: 1px solid #b42318;
}

.btn-danger:hover {
  background: #fef2f2;
}

.rack-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 28px;
  background: var(--navy-deep);
}

.rack-tab {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--navy-soft);
  background: transparent;
  color: #c9d6de;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rack-tab:hover {
  border-color: var(--orange);
  color: var(--white);
}

.rack-tab.active {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
}

.rack-tab .tab-count {
  font-weight: 400;
  opacity: 0.8;
  font-size: 0.75rem;
  margin-left: 4px;
}

.page {
  display: flex;
  gap: 20px;
  padding: 24px 28px;
  align-items: flex-start;
}

.content {
  flex: 1;
  min-width: 0;
  background: var(--white);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.view-header h1 {
  margin: 0;
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.view-header .occupancy {
  color: var(--ink-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.rack-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  background: var(--white);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  font-family: inherit;
  text-align: left;
}

.rack-card:hover {
  border-color: var(--orange);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.rack-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rack-card .card-meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin-bottom: 10px;
}

.fill-bar {
  height: 8px;
  border-radius: 999px;
  background: #e8eef4;
  overflow: hidden;
}

.fill-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--orange);
  transition: width 0.3s ease;
}

.rack-card .card-count {
  margin-top: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
}

.stock-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stock-row {
  display: flex;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  background: var(--white);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.stock-row:hover {
  border-color: var(--orange);
  box-shadow: var(--shadow);
}

.stock-image {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}

.stock-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.stock-no-image {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: center;
}

.stock-info {
  flex: 1;
  min-width: 0;
}

.stock-code {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.03em;
  margin-bottom: 8px;
  word-break: break-all;
}

.stock-locations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stock-location {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
  transition: all 0.15s ease;
}

.stock-location:hover {
  border-color: var(--orange);
  background: var(--orange-soft);
  color: #c25a10;
}

.stock-qty {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
}

.stock-qty .qty-number {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--orange);
  line-height: 1.1;
}

.stock-qty .qty-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.rack-grid {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.rack-cell {
  position: relative;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.rack-cell .cell-pos {
  position: absolute;
  top: 5px;
  left: 8px;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
  pointer-events: none;
}

.rack-cell:hover {
  border-color: var(--orange);
  background: var(--orange-soft);
}

/* A reel "picked up" for a tap-to-move. Stands out clearly on a busy rack. */
.rack-cell.armed {
  outline: 3px solid var(--orange);
  outline-offset: -1px;
  box-shadow: 0 0 0 4px var(--orange-soft);
  animation: armed-pulse 1.1s ease-in-out infinite;
}

@keyframes armed-pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--orange-soft); }
  50% { box-shadow: 0 0 0 7px var(--orange-soft); }
}

.rack-cell.drag-over {
  border-color: var(--orange);
  background: var(--orange-soft);
}

.rack-cell.has-epic {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 18px 6px 6px;
  text-align: center;
  overflow: hidden;
}

.rack-cell.has-epic .cell-pos {
  color: #9fb3c0;
}

.rack-cell.has-epic img {
  width: 100%;
  max-height: 110px;
  object-fit: contain;
  display: block;
  border-radius: 6px;
  background: var(--white);
}

.rack-cell.has-epic .epic-label {
  font-size: 0.72rem;
  line-height: 1.2;
  word-break: break-all;
}

/* Partial locations: a subtle dashed edge, plus a little "P" badge. */
.rack-cell.is-partial {
  border-style: dashed;
  border-color: var(--orange);
}

.partial-badge {
  position: absolute;
  top: 5px;
  right: 6px;
  z-index: 1;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--orange);
  color: var(--white);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* Texstrip-only locations: a little "TS" badge, top-left so it never sits under the "P". */
.texstrip-badge {
  position: absolute;
  top: 5px;
  right: 6px;
  z-index: 1;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--navy-soft);
  color: var(--white);
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.rack-cell.has-epic .mm-label {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--orange);
  letter-spacing: 0.02em;
}

/* Partial markers in the stock take. */
.stock-location.is-partial {
  border-color: var(--orange);
}

.stock-partial {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--orange);
  color: var(--white);
  font-size: 0.62rem;
  font-weight: 700;
}

@keyframes pulse-cell {
  0%, 100% { outline: 3px solid transparent; }
  50% { outline: 3px solid var(--orange); }
}

.rack-cell.pulse {
  animation: pulse-cell 0.7s ease 3;
}

.empty-note {
  color: var(--ink-muted);
}

.epic-panel {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Only shown on a single-rack page (toggled from render()). */
.epic-panel[hidden] {
  display: none;
}

.epic-panel h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--navy);
}

.epic-panel label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--navy);
}

.epic-panel input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  font-family: inherit;
}

.epic-panel input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  border-color: var(--orange);
}

/* Epic entry: text field plus camera-scan and product-search buttons. */
.epic-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.epic-input-row input {
  flex: 1;
  min-width: 0;
}

.epic-tool-btn {
  flex-shrink: 0;
  width: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.epic-tool-btn svg {
  width: 22px;
  height: 22px;
}

.epic-tool-btn:hover,
.epic-tool-btn:active {
  background: var(--orange-soft);
  border-color: var(--orange);
  color: #c25a10;
}

.epic-drag-chip {
  padding: 12px;
  border: 1px dashed var(--orange);
  border-radius: 10px;
  background: var(--orange-soft);
  color: #c25a10;
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  cursor: grab;
}

.epic-drag-chip:active {
  cursor: grabbing;
}

.trash-bin {
  padding: 14px;
  border: 2px dashed #b42318;
  border-radius: 10px;
  text-align: center;
  color: #b42318;
  font-weight: 700;
  font-size: 0.85rem;
  background: #fef2f2;
  cursor: pointer;
  transition: background 0.15s ease;
}

.trash-bin.drag-over,
.trash-bin:active {
  background: #fecaca;
}

.hint {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

kbd {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.72rem;
  font-family: inherit;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--navy-deep);
  color: var(--white);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}

.toast.warn {
  background: var(--orange);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.hide {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* ---- Sign-in gate ------------------------------------------------------ */
body.auth-locked {
  overflow: hidden;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 30%, var(--navy) 0%, var(--navy-deep) 70%);
  /* Fast taps on the PIN pad should never be read as a double-tap zoom. */
  touch-action: manipulation;
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--white);
  border-radius: 20px;
  padding: 30px 26px 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.auth-card.shake {
  animation: auth-shake 0.4s ease;
}

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.auth-logo {
  height: 34px;
  width: auto;
  margin-bottom: 16px;
}

.auth-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.auth-sub {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-top: 4px;
}

.auth-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 20px 0 6px;
  min-height: 16px;
}

.auth-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.auth-dot.filled {
  background: var(--orange);
  border-color: var(--orange);
}

.auth-error {
  min-height: 18px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #b42318;
  margin-bottom: 10px;
}

.auth-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.auth-key {
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 600;
  padding: 16px 0;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--navy);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
  /* Stop mobile browsers waiting for a double-tap (which zooms the page)
     when the PIN is tapped in quickly. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.auth-key:hover {
  background: var(--orange-soft);
  border-color: var(--orange);
}

.auth-key:active {
  transform: scale(0.95);
}

.auth-key-alt {
  color: var(--ink-muted);
  font-size: 1.6rem;
}

.auth-key-enter {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
  font-size: 1.5rem;
}

.auth-key-enter:hover {
  background: #d9620f;
  color: var(--white);
}

/* ---- Header user chip -------------------------------------------------- */
.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--navy-deep);
  border: 1px solid var(--navy-soft);
}

.user-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--white);
  white-space: nowrap;
}

.user-role {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--navy-deep);
  background: var(--orange);
  padding: 2px 7px;
  border-radius: 999px;
}

.user-btn {
  padding: 7px 14px;
  font-size: 0.82rem;
}

/* ---- Modals (manage team / activity log) ------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
  background: rgba(0, 14, 40, 0.55);
}

.modal {
  width: 100%;
  max-width: 620px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--navy);
}

.modal-body {
  padding: 20px 22px 24px;
}

.modal-subhead {
  margin: 22px 0 12px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--navy);
}

.modal-warning {
  padding: 10px 14px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #f3b0a9;
  color: #b42318;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ---- Inline product name / pack size fields (Manage products) --------- */
.product-field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.product-field-inline input {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--navy);
}

.product-field-inline input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  border-color: var(--orange);
}

/* ---- Barcode scanner --------------------------------------------------- */
.scanner-modal {
  max-width: 460px;
}

.scanner-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner-reticle {
  position: absolute;
  inset: 18% 12%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.scanner-hint {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-align: center;
}

.scanner-error:not(:empty) {
  margin-top: 12px;
}

/* ---- Product picker (search / drill-down) ----------------------------- */
.picker-modal {
  max-width: 480px;
}

.picker-search {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.95rem;
}

.picker-search:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  border-color: var(--orange);
}

.picker-crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin: 12px 0;
  font-size: 0.8rem;
}

.picker-crumb {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--orange);
  cursor: pointer;
  padding: 2px 2px;
  touch-action: manipulation;
}

.picker-crumb.current {
  color: var(--ink-muted);
  cursor: default;
}

.picker-crumb-sep {
  color: var(--ink-muted);
}

.picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.picker-item:hover,
.picker-item:active {
  border-color: var(--orange);
  background: var(--orange-soft);
}

.picker-thumb {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.picker-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.picker-noimg {
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.picker-item-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.picker-item-main {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--navy);
  word-break: break-word;
}

.picker-item-sub {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-weight: 500;
}

.picker-item-count {
  flex-shrink: 0;
  min-width: 24px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.picker-epic .picker-item-body {
  flex: 1;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.team-table,
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.team-table th,
.audit-table th {
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.team-table td,
.audit-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.team-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.tag {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--navy);
  color: var(--white);
  margin-left: 6px;
}

.tag-warn {
  background: var(--orange);
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 4px;
}

.product-row {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.product-thumb {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.product-no-image {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: center;
}

.product-meta {
  flex: 1;
  min-width: 0;
}

.product-epic {
  font-weight: 700;
  color: var(--navy);
  word-break: break-all;
}

.product-code {
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.product-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.product-move {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.product-move select {
  font: inherit;
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--navy);
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
}

/* ---- Product folders (Manage products) ---- */
.product-folder {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--white);
}

.product-folder > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 700;
  color: var(--navy);
  background: var(--bg);
  list-style: none;
}

.product-folder > summary::-webkit-details-marker {
  display: none;
}

.product-folder > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--ink-muted);
  transition: transform 0.15s ease;
}

.product-folder[open] > summary::before {
  transform: rotate(90deg);
}

.product-folder .folder-name {
  flex: 1;
}

.folder-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

.product-folder[open] > summary .folder-count {
  background: var(--bg);
}

.folder-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
}

.folder-body .product-row {
  background: var(--white);
}

/* ---- Folder admin ---- */
.folder-admin {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.folder-admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}

.folder-admin-name {
  flex: 1;
  font-weight: 700;
  color: var(--navy);
  min-width: 0;
  word-break: break-word;
}

.pin-reveal {
  border: 2px solid var(--orange);
  background: var(--orange-soft);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 18px;
  text-align: center;
}

.pin-reveal-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #c25a10;
}

.pin-reveal-code {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--navy);
  margin: 6px 0;
  font-variant-numeric: tabular-nums;
}

.pin-reveal-note {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-muted);
  margin-bottom: 12px;
}

.add-note {
  font-size: 0.8rem;
  color: var(--ink-muted);
  margin: 0 0 12px;
}

.add-user-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.add-user-form .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.add-user-form label {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--navy);
}

.add-user-form input[type="text"] {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.9rem;
}

.add-user-form input:focus {
  outline: 2px solid var(--orange);
  outline-offset: 1px;
  border-color: var(--orange);
}

.add-user-form .check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--ink);
}

.add-error {
  min-height: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #b42318;
}

.audit-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.audit-scroll {
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.audit-table {
  font-size: 0.8rem;
}

.audit-table th {
  position: sticky;
  top: 0;
  background: var(--white);
}

.audit-time {
  white-space: nowrap;
  color: var(--ink-muted);
}

.audit-user {
  white-space: nowrap;
  font-weight: 600;
  color: var(--navy);
}

.audit-detail {
  color: var(--ink-muted);
}

@media (max-width: 860px) {
  .page {
    flex-direction: column;
    align-items: stretch;   /* let content fill the width, not hug content */
  }

  .content {
    width: 100%;
  }

  /* On a phone/tablet the rack is tall and scrolls, so dock the epic controls
     as a sticky bottom bar — scan and place/remove without scrolling away.
     (It only appears on rack pages; render() hides it elsewhere.) */
  .epic-panel {
    position: fixed;
    top: auto;            /* clear the sticky top:20px, or it stretches full-height */
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    z-index: 50;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 20px rgba(0, 14, 40, 0.16);
  }

  /* Trim the bar to essentials: heading, field label and the (touch-useless)
     drag chip all go; the scan box grows, the bin becomes a compact button. */
  .epic-panel h2,
  .epic-panel label,
  .epic-panel .epic-drag-chip {
    display: none;
  }

  .epic-panel input {
    flex: 1;
    min-width: 0;
  }

  .trash-bin {
    flex: 0 0 auto;
    padding: 12px 14px;
  }

  .trash-bin .trash-label {
    display: none;   /* just the bin icon on narrow screens */
  }

  /* Keep the last rack rows clear of the docked bar. */
  body.on-rack-page .page {
    padding-bottom: 96px;
  }

  .stock-row {
    flex-wrap: wrap;
  }

  .stock-qty {
    flex-direction: row;
    gap: 6px;
    align-items: baseline;
  }
}

/* =====================================================================
   Touch & tablet (iPad) support
   ===================================================================== */

/* Stop iOS from firing a slow 300ms delay / zoom on taps, and hide the grey
   tap flash and the long-press callout on the interactive bits. */
.btn,
.rack-tab,
.rack-cell,
.stock-location,
.epic-drag-chip,
.trash-bin,
.rack-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* A reel cell shouldn't select its text or pop the iOS callout menu when
   tapped and held. */
.rack-cell {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* On any touch device, give fingers bigger targets regardless of screen size. */
@media (pointer: coarse) {
  .rack-cell {
    min-height: 108px;
  }

  .rack-tab {
    padding: 10px 18px;
    font-size: 0.9rem;
  }

  .btn {
    padding: 11px 22px;
  }

  .stock-location {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .epic-panel input,
  .search-wrap input {
    font-size: 16px; /* keeps iOS Safari from auto-zooming the page on focus */
  }
}

/* iPad-and-down layout: let the rack grid scroll sideways rather than crushing
   cells, and keep the tabs usable when there are lots of racks. */
@media (max-width: 1024px) {
  .page {
    padding: 18px;
  }

  .rack-tabs {
    padding: 12px 16px;
    overflow-x: auto;
    flex-wrap: nowrap;              /* one scrollable row instead of a tall wall */
    -webkit-overflow-scrolling: touch;
  }

  .rack-tab {
    flex: 0 0 auto;
  }

  .content {
    padding: 16px;
    overflow-x: auto;              /* rack grid can scroll if it's wider than the screen */
    -webkit-overflow-scrolling: touch;
  }

  .top-bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .header-controls {
    flex: 1;
    justify-content: flex-end;
  }

  .search-wrap {
    flex: 1;
  }

  .search-wrap input {
    min-width: 0;
    width: 100%;
  }
}

/* "Rotate your device" prompt. A browser can't force orientation (iOS Safari
   has no lock API), so on a phone-sized screen held in portrait we cover the
   rack page and ask the user to turn sideways, where the whole bay fits. iPads
   fit a rack in portrait, so the width cap keeps this to phones. */
#rotateNotice {
  display: none;
}

@media (orientation: portrait) and (max-width: 700px) {
  body.on-rack-page #rotateNotice {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 32px;
    text-align: center;
    background: var(--navy-deep);
    color: var(--white);
  }

  /* Nothing behind the prompt should be tappable. */
  body.on-rack-page .epic-panel {
    display: none;
  }

  #rotateNotice .rotate-graphic {
    width: 84px;
    height: 84px;
    color: var(--orange);
    animation: rotate-hint 2.4s ease-in-out infinite;
  }

  #rotateNotice .rotate-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  #rotateNotice .rotate-sub {
    margin: 0;
    max-width: 26ch;
    color: #c9d6de;
    font-size: 0.95rem;
    line-height: 1.5;
  }

  #rotateNotice #rotateBack {
    margin-top: 8px;
  }
}

@keyframes rotate-hint {
  0%, 55% { transform: rotate(0deg); }
  75%, 100% { transform: rotate(-90deg); }
}

/* Phones: keep each rack cell a legible size and let the rack scroll sideways
   (a rack is a physical grid, so we keep its shape rather than reflow it), and
   show the rack overview two-up instead of one cramped column. */
@media (max-width: 640px) {
  .rack-grid {
    --cell-min: 120px;
    gap: 6px;
    padding: 10px;
  }

  .overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .rack-card {
    padding: 12px;
  }

  .view-header h1 {
    font-size: 1.15rem;
  }

  .content {
    padding: 12px;
  }
}

.texstrip-badge {
  position: absolute;
  top: 5px;
  right: 6px;
  z-index: 1;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--navy-soft);
  color: var(--white);
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}