/* Design tokens — ported from prototype's CSS (/tmp/warehouse-styles.pretty.css:1616) */
:root {
  --black: #171717;
  --white: #fff;
  --grey-light: #fafafa;
  --grey-medium: #a9a9a9;
  --mint: #00fba9;
  --yellow: #f5b700;
  --coral: #ff4c00;
  --blue: #3941eb;
  --purple: #a900fb;

  --font-sans: "Atkinson Hyperlegible Next", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;

  --nav-height: 64px;
  --topbar-height: 48px;
  --radius-pill: 9999px;

  --transition: all 150ms ease-out;
}

:root.dark {
  --black: #eeeeee;
  --white: #242424;
  --grey-light: #141414;
  --grey-medium: #6b6b6b;
}

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

html,
body {
  height: 100%;
}

body {
  color: var(--black);
  background: var(--grey-light);
  font-family: var(--font-sans);
  font-weight: 300;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Top bar */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--grey-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
}
.top-bar-brand {
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.top-bar-brand:hover { opacity: 0.7; }
.top-bar-logo {
  height: 32px;
  width: auto;
}
:root.dark .top-bar-logo { filter: invert(1); }
.top-bar-user {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--black);
  border-radius: 8px;
  color: var(--black);
  transition: var(--transition);
}
.top-bar-user:hover { background: var(--grey-light); }

#app {
  min-height: calc(100vh - var(--nav-height) - var(--topbar-height));
  padding-top: var(--topbar-height);
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 300;
  line-height: 1.1;
}

h1 { font-size: 1.875rem; font-weight: 700; color: var(--black); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }

p { color: var(--black); font-weight: 300; }

a { color: inherit; text-decoration: none; }
/* Browsers set `a:hover { text-decoration: underline }` with higher
   specificity than the base `a` selector above. Restate `none` on the
   :hover state so text inside card-style links (e.g. dashboard queue
   rows) doesn't get a stray underline on hover. */
a:hover { text-decoration: none; }

button {
  font-family: inherit;
  font-weight: 300;
  cursor: pointer;
  background: none;
  border: none;
}

input, select, textarea {
  font-family: inherit;
  font-weight: 300;
  background: var(--white);
  border: 1px solid var(--grey-light);
  padding: 0.75rem 1rem;
  color: var(--black);
  width: 100%;
  transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--black);
}

/* Shared utility-ish classes */
.mono { font-family: var(--font-mono); }
.uppercase { text-transform: uppercase; letter-spacing: 0.05em; }
.small { font-size: 0.75rem; }
.x-small { font-size: 0.625rem; }
.hidden { display: none !important; }
.text-grey { color: var(--grey-medium); }
.text-coral { color: var(--coral); }
.text-blue { color: var(--blue); }
.text-mint { color: var(--mint); }
.text-white { color: var(--white); }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Card */
.card {
  background: var(--white);
  border: 1px solid var(--grey-light);
  padding: 1rem;
  transition: var(--transition);
}
.card + .card { margin-top: 0.75rem; }
a.card:focus,
a.card:focus-visible { outline: none; }

.queue-row {
  display: block;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--grey-light);
}
.queue-row:first-child { padding-top: 0.25rem; }
.queue-row:focus,
.queue-row:focus-visible { outline: none; }

/* Paginator — numbered button row for client-paginated lists
   (Recent + Drafts on the home page). Sized for tablet hit targets. */
.paginator {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 0.75rem;
}
.paginator-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 1px solid var(--grey-light);
  background: var(--white);
  color: var(--black);
  font: inherit;
  font-size: 0.95rem;
  border-radius: 9999px;
  cursor: pointer;
}
.paginator-btn:hover:not(.is-disabled):not(.is-active) { border-color: var(--black); }
.paginator-btn.is-active {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
  cursor: default;
}
.paginator-btn.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.paginator-ellipsis {
  display: inline-flex;
  align-items: center;
  padding: 0 0.25rem;
  color: var(--grey-medium);
}

/* Dashboard stats collapse toggle — chevron button above the KPI
   grid that hides/shows the stats so the operator can reclaim screen
   space for the queue list. Default state is expanded; chevron points
   up when expanded (tap to collapse) and right when collapsed. */
.dashboard-stats-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}
.dashboard-stats-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 44px;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--grey-light);
  border-radius: 9999px;
  background: var(--white);
  color: var(--grey-medium);
  font: inherit;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.dashboard-stats-toggle:hover { border-color: var(--black); color: var(--black); }
.dashboard-stats-toggle-chevron {
  display: inline-flex;
  transform: rotate(-90deg);
  transition: transform 150ms ease-out;
}
.dashboard-stats-toggle.is-collapsed .dashboard-stats-toggle-chevron {
  transform: rotate(0deg);
}

/* Paginator-rows — Material-style "Rows per page" footer for the
   dashboard queue lists. Distinct from .paginator (numbered buttons)
   which is used for the home-page localStorage lists. */
.queue-list-wrapper {
  display: flex;
  flex-direction: column;
}
.paginator-rows {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--grey-light);
  font-size: 0.875rem;
}
.paginator-rows-left,
.paginator-rows-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.paginator-rows-label {
  color: var(--grey-medium);
}
.paginator-rows-select {
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  width: auto;
  border: 1px solid var(--grey-light);
  background: var(--white);
  color: var(--black);
  font: inherit;
}
.paginator-rows-select:focus { border-color: var(--black); }
.paginator-rows-range {
  color: var(--grey-medium);
  margin-right: 0.25rem;
}
.paginator-rows-arrow {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.5rem;
  border: 1px solid var(--grey-light);
  background: var(--white);
  color: var(--black);
  border-radius: 9999px;
  font-size: 1.1rem;
  line-height: 1;
}
.paginator-rows-arrow:hover:not(.is-disabled) { border-color: var(--black); }
.paginator-rows-arrow.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Page layout */
.page {
  padding: 1rem;
  max-width: 560px;
  margin: 0 auto;
}
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; flex: 1; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-height: 48px;
  transition: var(--transition);
  border: 1px solid transparent;
}
.btn-primary { background: var(--black); color: var(--white); }
.btn-primary:hover { filter: brightness(1.2); }
.btn-blue { background: var(--blue); color: var(--white); }
.btn-blue:hover { filter: brightness(0.95); }
.btn-coral { background: var(--coral); color: var(--white); }
.btn-outline { border: 1px solid var(--grey-medium); color: var(--black); background: var(--white); }
.btn-outline:hover { border-color: var(--black); }
.btn-sm { min-height: 36px; padding: 0.5rem 1rem; font-size: 0.75rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-icon { padding: 0.5rem; min-height: auto; border-radius: 0; color: var(--grey-medium); }
.btn-icon:hover { color: var(--black); background: var(--white); }
.btn-full { width: 100%; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 200;
}
.badge-grey { background: var(--grey-light); color: var(--black); }
.badge-blue { background: var(--blue); color: var(--white); border-radius: var(--radius-pill); padding: 0.25rem 0.5rem; }
.badge-coral { background: var(--coral); color: var(--white); border-radius: var(--radius-pill); padding: 0.25rem 0.5rem; }
.badge-purple { background: var(--purple); color: var(--white); border-radius: var(--radius-pill); padding: 0.25rem 0.5rem; }
.badge-mint { background: var(--mint); color: var(--black); border-radius: var(--radius-pill); padding: 0.25rem 0.5rem; }

/* Form group */
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey-medium);
  margin-bottom: 0.25rem;
}
.field .error {
  color: var(--coral);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* Status stripes (for draft cards) */
.stripe { border-left: 4px solid var(--grey-medium); }
.stripe.stripe-coral { border-left-color: var(--coral); }
.stripe.stripe-blue { border-left-color: var(--blue); }
.stripe.stripe-mint { border-left-color: var(--mint); }

/* Bottom nav */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--white);
  border-top: 1px solid var(--grey-light);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--grey-medium);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 200;
  transition: var(--transition);
  min-height: 48px;
}
.nav-item-icon {
  opacity: 0.8;
  transition: var(--transition);
  color: inherit;
}

.nav-item-icon.active {
  opacity: 1;
}

.nav-item-label {
  opacity: 0.9;
}

.nav-item.active,
.nav-item:hover {
  color: var(--black);
}

.nav-item.active .nav-item-icon,
.nav-item:hover .nav-item-icon {
  opacity: 1;
  transform: translateY(-1px);
  color: var(--black);
}

.nav-item.active .nav-item-label {
  opacity: 1;
}

.nav-item.active {
  background: var(--grey-light);
}

:root.dark .nav-item.active,
:root.dark .nav-item.active .nav-item-icon {
  color: #fff;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--grey-light);
  border: 1px solid rgba(169, 169, 169, 0.45);
  margin-bottom: 1rem;
}
.tab {
  flex: 1;
  padding: 0.625rem 1rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  color: var(--grey-medium);
  text-align: center;
  transition: var(--transition);
}
.tab.active { background: var(--blue); color: var(--white); }

.dashboard-top {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.dashboard-page {
  max-width: none;
}

.dashboard-range-row {
  display: flex;
  justify-content: flex-end;
}

.dashboard-scope {
  width: 100%;
  margin-bottom: 0;
  border-color: rgba(169, 169, 169, 0.45);
  background: var(--white);
}

.dashboard-range {
  min-width: 320px;
  margin-bottom: 0;
  border-color: rgba(169, 169, 169, 0.45);
  background: var(--white);
}

.dashboard-range .tab {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
}

.dashboard-scope .tab.active,
.dashboard-range .tab.active {
  background: var(--mint);
  color: var(--black);
}

.dashboard-range-panel {
  margin-bottom: 1rem;
  border-color: rgba(169, 169, 169, 0.45);
}

.dashboard-range-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey-medium);
}

.dashboard-range-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Scan CTA (home) */
.scan-cta {
  display: block;
  margin-bottom: 1.5rem;
  padding: 2rem;
  text-align: center;
  background: var(--blue);
  color: var(--white);
  transition: var(--transition);
}
.scan-cta:hover { opacity: 0.9; }
.scan-cta h2 { font-size: 1.5rem; margin: 0.75rem 0 0.25rem; }
.scan-cta p { color: rgba(255, 255, 255, 0.7); font-size: 0.875rem; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stats-grid-wide {
  grid-template-columns: repeat(2, 1fr);
}

.stats-grid-secondary {
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid rgba(169, 169, 169, 0.45);
  padding: 1rem;
}
.stat-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.stat-card .label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--grey-medium);
  font-weight: 200;
}
.stat-card .label-with-tooltip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.stat-card .value {
  font-size: 1.75rem;
  font-weight: 300;
  color: var(--black);
  margin-top: 0.25rem;
}

.stat-card-delta {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--grey-medium);
}

/* Inline info tooltip trigger on dashboard stat labels. */
.tooltip-trigger[data-tooltip] {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  color: var(--grey-medium);
  opacity: 0.9;
  cursor: help;
}
.tab .tooltip-trigger[data-tooltip] {
  margin-left: 0.25rem;
  transform: translateY(-3px);
}
.tooltip-trigger[data-tooltip]:hover,
.tooltip-trigger[data-tooltip]:focus-visible {
  opacity: 1;
  color: var(--black);
}
.tab:focus-visible .tooltip-trigger[data-tooltip] {
  opacity: 1;
}
.tooltip-trigger[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 190px;
  max-width: 260px;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  background: var(--black);
  color: var(--white);
  font-size: 0.7rem;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: normal;
  font-family: var(--font-sans);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.tooltip-trigger[data-tooltip]:hover::after,
.tooltip-trigger[data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}
.tab:focus-visible .tooltip-trigger[data-tooltip]::after {
  opacity: 1;
  visibility: visible;
}

@media (min-width: 640px) {
  .stats-grid-wide {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Scanner video */
video.scanner {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 4 / 3;
  background: var(--black);
  object-fit: cover;
  display: block;
  margin: 0 auto;
}

.scan-method-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.scan-method-btn {
  min-height: 34px;
  border: 1px solid var(--grey-medium);
  border-radius: var(--radius-pill);
  color: var(--grey-medium);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: var(--transition);
}

.scan-method-btn.active {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--white);
}

/* Toast */
#toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1rem;
  background: var(--black);
  color: var(--white);
  font-size: 0.875rem;
  z-index: 200;
  max-width: 90%;
  transition: opacity 150ms ease-out;
}
#toast[hidden] { opacity: 0; pointer-events: none; }

@keyframes pulse-opacity {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.pulse { animation: pulse-opacity 1.5s ease-in-out infinite; }

/* Wizard step nav */
.step-indicator {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
}
.step-indicator .step {
  flex: 1;
  height: 2px;
  background: var(--grey-light);
}
.step-indicator .step.active,
.step-indicator .step.done { background: var(--black); }

/* Processing sorting step — compact tablet layout */
.processing-sorting-card {
  padding: 0.75rem;
}
.processing-sorting-card:hover {
  border-color: var(--grey-light);
}
.processing-sorting-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.processing-sorting-search {
  margin-bottom: 0.5rem;
}
.processing-sorting-search input {
  padding: 0.55rem 0.75rem;
  border-color: var(--black);
}
.processing-materials-list {
  padding-right: 0;
}
.processing-material-section {
  margin-bottom: 0.5rem;
  border-top: 1px solid var(--grey-light);
  padding-top: 0.5rem;
}
.processing-sort-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.processing-material-row,
.processing-contamination-row {
  padding: 0.3rem 0.2rem;
}
.processing-material-row.is-active,
.processing-contamination-row.is-active {
  background: var(--grey-light);
}
.processing-material-toggle {
  width: 20px;
  height: 20px;
  border: 2px solid var(--grey-medium);
  color: var(--black);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.processing-material-toggle.is-active {
  border-color: var(--mint);
  background: var(--mint);
}
.processing-material-main {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  flex: 1;
  text-align: left;
}
.processing-material-weight {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.processing-material-weight input {
  padding: 0.45rem 0.55rem;
  text-align: right;
}
.processing-sorting-actions {
  margin-top: 0.75rem;
  /* PEN-853: keep Back / Search / Continue reachable on long material
     lists. Stays above the fixed bottom nav at rest; lifts above the
     iOS soft keyboard when a weight input is focused (see
     --keyboard-inset, set by the visualViewport tracker in
     processing.js). max() picks whichever is currently larger so a
     keyboard always wins over the nav offset. */
  position: sticky;
  bottom: max(
    calc(var(--nav-height) + env(safe-area-inset-bottom, 0px)),
    var(--keyboard-inset, 0px)
  );
  background: var(--white);
  padding: 0.5rem 0;
  z-index: 10;
}
.processing-btn-back {
  flex: 0 0 auto;
  min-width: 92px;
  min-height: 42px;
  padding: 0.5rem 0.9rem;
}
.processing-btn-search {
  flex: 0 0 auto;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border-color: var(--black);
  font-size: 1.2rem;
}
.processing-btn-search.is-active {
  background: var(--grey-light);
}
.processing-btn-continue {
  flex: 1 1 auto;
  min-height: 54px;
}

/* PEN-853: iPad layout — expand to full viewport at tablet+.
   Hits any iPad (810pt 9th gen, 820pt 10th gen / Air, 834pt Pro 11",
   1024pt Pro 12.9"); intentionally excludes iPad Mini 6th gen (744pt). */
@media (min-width: 768px) {
  .page {
    max-width: 760px;
    padding: 1.25rem;
  }

  /* Top bar: keep position: fixed full-width so the white background
     covers edge-to-edge, but pad inner content so brand + user icon
     align with the .page content column. */
  #top-bar {
    padding: 0 max(1rem, calc((100vw - 760px) / 2 + 1rem));
  }

  /* Bottom nav: same full-width bar, but center the three nav items
     instead of stretching them across 820pt. */
  #bottom-nav {
    justify-content: center;
    gap: 4rem;
  }
  .nav-item {
    flex: 0 0 auto;
    min-width: 96px;
  }

  /* Sorting step: ensure tap targets meet Apple HIG 44pt minimum.
     The compact mobile spacing is overridden here on tablet only. */
  .processing-sort-row {
    min-height: 44px;
  }
  .processing-material-toggle {
    width: 28px;
    height: 28px;
  }
}
