/* ============================================================================
   inventory.css — app-shell layout patterns specific to the inventory app.
   Depends on: tokens.css + components.css
   
   This file is small on purpose. Page-specific composition lives here
   (two-pane component detail, dashboard grid, scan camera shell, etc.).
   Everything else is in components.css.
============================================================================ */

/* ─── APP SHELL ───────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--color-bg-page);
}

/* Main page container — gutter + max-width */
.page {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--sp-6);
  width: 100%;
}
@media (max-width: 640px) {
  .page { padding: var(--sp-4); }
}

/* Page header — title row + actions */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) 0 var(--sp-5);
}
.page-header__title {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-fg-default);
  line-height: 1.1;
}
.page-header__kicker {
  font-size: var(--fs-sm);
  color: var(--color-fg-muted);
  margin-bottom: 4px;
}
.page-header__actions {
  display: flex; align-items: center; gap: var(--sp-2);
  flex-shrink: 0;
}

/* Toolbar — search + filter + sort row */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) 0 var(--sp-4);
  flex-wrap: wrap;
}
.toolbar__search { flex: 1; min-width: 240px; max-width: 480px; }
.toolbar__group { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
/* .select defaults to width:100%, which collapses each filter dropdown onto
   its own row inside the flex toolbar group. Constrain them to a natural
   width on wide viewports so they sit side-by-side. The mobile media query
   below already overrides with flex:1 to stretch them full-width. */
.toolbar__group .select { width: auto; min-width: 180px; }
.toolbar__count {
  font-size: var(--fs-sm);
  color: var(--color-fg-muted);
}

/* Filter rail (active filters below toolbar) */
.filter-rail {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 0 var(--sp-3);
  flex-wrap: wrap;
}

/* ─── DASHBOARD ───────────────────────────────────────────────────────── */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--sp-4);
}
@media (max-width: 880px) {
  .dashboard-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 520px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

.kpi {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1_5);
  min-height: 110px;
}
.kpi__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-fg-muted);
}
.kpi__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 32px;
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-fg-default);
  line-height: 1;
}
.kpi__value--currency::before { content: '$'; font-weight: var(--fw-medium); color: var(--color-fg-muted); margin-right: 1px; }
.kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.kpi__delta--up { color: var(--color-success-fg); }
.kpi__delta--down { color: var(--color-danger-fg); }
.kpi__sub { font-size: var(--fs-xs); color: var(--color-fg-muted); }

/* ─── COMPONENT DETAIL — two-pane ────────────────────────────────────── */

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: var(--sp-5);
  align-items: start;
}
@media (max-width: 1024px) {
  .detail-layout { grid-template-columns: 1fr; }
}

.detail-hero {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-5);
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--sp-5);
}
.detail-hero__photo {
  width: 96px; height: 96px;
  border-radius: var(--radius-md);
  background: var(--ink-100);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-400);
  overflow: hidden;
}
@media (min-width: 768px) {
  .detail-hero__photo { width: 128px; height: 128px; }
}
.detail-hero__title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  line-height: 1.15;
}
.detail-hero__meta {
  display: flex; gap: var(--sp-2);
  flex-wrap: wrap;
  margin-top: var(--sp-1_5);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-fg-muted);
}

/* Big numeric value used on detail page */
.big-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 44px;
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  line-height: 1;
}
.big-num--ok { color: var(--color-success-fg); }
.big-num--low { color: var(--color-danger-fg); }

/* Two-column stat row */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  background: var(--color-border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border-subtle);
}
.stat-row__cell {
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-bg-surface);
}
.stat-row__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-fg-muted);
}
.stat-row__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  margin-top: 2px;
}

/* ─── COMPONENT IMAGE PLACEHOLDER — schematic-style ──────────────────── */

.comp-tile {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--ink-100);
  color: var(--ink-500);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.comp-tile--sm { width: 28px; height: 28px; border-radius: 5px; }
.comp-tile--lg { width: 48px; height: 48px; border-radius: 8px; }
.comp-tile--xl { width: 96px; height: 96px; border-radius: var(--radius-md); }

/* Per-category tints. These keep the parts visually distinct in dense lists
   without committing to fake photos. */
.comp-tile--resistors   { background: #F5E7D4; color: #A8743A; }
.comp-tile--capacitors  { background: #DFE9D8; color: #4A6B35; }
.comp-tile--diodes      { background: #F1D9DA; color: #9B3C40; }
.comp-tile--transistors { background: #D8E1EF; color: #3A5278; }
.comp-tile--ics         { background: #1A1D20; color: #D3D7DA; }
.comp-tile--modules     { background: #1A1D20; color: #7EE0C2; }
.comp-tile--connectors  { background: #EBE2D4; color: #8A6A35; }
.comp-tile--hardware    { background: #E2E2E2; color: #444; }
.comp-tile--pcbs        { background: #0C2317; color: #6ACF8A; }

/* ─── BOM ROW (kit detail) ────────────────────────────────────────────── */

.bom-row {
  display: grid;
  grid-template-columns: 36px 1fr 80px 80px 80px;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border-subtle);
}
.bom-row:last-child { border-bottom: 0; }
.bom-row--bottleneck {
  background: linear-gradient(90deg, var(--color-danger-bg) 0%, transparent 60%);
}

/* ─── MOVEMENT LOG ────────────────────────────────────────────────────── */

.log-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto auto auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--color-border-subtle);
}
.log-row__time {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-fg-muted);
  white-space: nowrap;
}
.log-row__delta {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  text-align: right;
  min-width: 50px;
}
.log-row__delta--up { color: var(--color-success-fg); }
.log-row__delta--down { color: var(--color-danger-fg); }

/* ─── DAY DIVIDER (movements) ─────────────────────────────────────────── */

.day-divider {
  position: sticky; top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-4);
  background: var(--color-bg-sunken);
  border-bottom: 1px solid var(--color-border-default);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-fg-secondary);
  z-index: 1;
}

/* ─── SCAN — full-bleed camera shell ──────────────────────────────────── */

.scan-stage {
  position: relative;
  background: #0a0b0d;
  color: #fff;
  border-radius: var(--radius-xl);
  overflow: hidden;
  aspect-ratio: 9 / 16;
}
.scan-stage__viewfinder {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 35%, #2a2d33 0%, #0a0b0d 75%);
}
.scan-stage__reticle {
  position: absolute;
  left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  width: 220px; height: 220px;
  pointer-events: none;
}
.scan-stage__reticle::before,
.scan-stage__reticle::after,
.scan-stage__reticle > div::before,
.scan-stage__reticle > div::after {
  content: '';
  position: absolute;
  width: 30px; height: 30px;
  border: 2px solid var(--brand-500);
}
.scan-stage__reticle::before { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scan-stage__reticle::after  { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scan-stage__reticle > div::before { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scan-stage__reticle > div::after  { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scan-stage__reticle > div { position: absolute; inset: 0; }

/* ─── MERGE-DUPLICATES STAGE ──────────────────────────────────────────── */

.merge-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}
.merge-stage__card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  cursor: pointer;
  position: relative;
}
.merge-stage__card.is-keep {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 1px var(--brand-500);
}
.merge-stage__card.is-keep::before {
  content: 'KEEP';
  position: absolute;
  top: -10px; left: 12px;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  background: var(--brand-500); color: #fff;
  padding: 2px 6px; border-radius: 4px;
}
.merge-stage__card.is-discard {
  opacity: 0.6;
  background: var(--color-bg-sunken);
}
.merge-stage__card.is-discard::before {
  content: 'DISCARD';
  position: absolute;
  top: -10px; left: 12px;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  background: var(--color-fg-muted); color: #fff;
  padding: 2px 6px; border-radius: 4px;
}

/* ─── KIT TILE (kits grid on mobile) ──────────────────────────────────── */

.kit-tile {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-subtle);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.kit-tile__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kit-tile__num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  line-height: 1;
}
.kit-tile__name {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
  line-height: 1.2;
  min-height: 32px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── EMPTY UTILITY HELPERS ───────────────────────────────────────────── */

.row    { display: flex; align-items: center; }
.row-h  { display: flex; align-items: center; gap: var(--sp-2); }
.col    { display: flex; flex-direction: column; }
.col-h  { display: flex; flex-direction: column; gap: var(--sp-2); }
.spacer { flex: 1; }
.gap-1  { gap: var(--sp-1); }
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.gap-5  { gap: var(--sp-5); }
.mt-3   { margin-top: var(--sp-3); }
.mt-4   { margin-top: var(--sp-4); }
.mt-5   { margin-top: var(--sp-5); }
.mt-6   { margin-top: var(--sp-6); }
.text-right { text-align: right; }

/* ─── APP NAV EXTRAS (purchaser select, user chip, signout) ────────────── */

#nav-bar { position: sticky; top: 0; z-index: var(--z-nav); }

.select--nav {
  height: 32px;
  padding: 0 var(--sp-7) 0 var(--sp-3);
  font-size: var(--fs-sm);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-page);
  width: auto;
  min-width: 150px;
}
.app-nav__user {
  font-size: var(--fs-sm);
  color: var(--color-fg-muted);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-nav__signout {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--color-fg-secondary);
  text-decoration: none;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
}
.app-nav__signout:hover { color: var(--color-danger-fg); background: var(--color-bg-sunken); text-decoration: none; }

/* Responsive nav — hide bottom tab-bar on desktop, hide section links + brand
   text on mobile (the bottom tab-bar covers them). */
.tab-bar { display: none; }
@media (max-width: 768px) {
  .app-nav__sections { display: none; }
  .nav-brand-text { display: none; }
  .app-nav__user { display: none; }
  .app-nav { padding: 0 var(--sp-4); gap: var(--sp-3); }
  .tab-bar { display: grid; }
  /* Reserve space so the fixed tab-bar doesn't cover content */
  body { padding-bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom, 0)); }
}
/* tokens.css scopes auto-dark to desktop. components.css still ships a
   dark-mode tab-bar background rule that fires on mobile when the OS
   reports dark — override it back to light so the bar matches the (light)
   page on mobile. data-theme='dark' (explicit user pick) stays dark. */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  :root[data-theme='auto'] .tab-bar,
  :root:not([data-theme]) .tab-bar {
    background: rgba(255, 255, 255, 0.92);
  }
}

/* ─── MOBILE — universal polish ──────────────────────────────────────────
   Applies to every page. Tightens padding, prevents the iOS zoom-on-focus
   trap, stacks the page-header so titles and action buttons each get a
   full row, makes the kv-list readable in 390px, and turns modals into
   bottom-sheet style overlays. Page-specific overrides (component-detail
   hero, two-column form grids) live alongside the page markup. */
@media (max-width: 640px) {
  .page { padding: var(--sp-3); }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    padding: var(--sp-2) 0 var(--sp-3);
    gap: var(--sp-3);
  }
  .page-header__title { word-break: break-word; font-size: var(--fs-2xl); line-height: 1.15; }
  .page-header__actions { flex-wrap: wrap; gap: var(--sp-2); }
  .page-header__actions .btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 var(--sp-3);
  }

  .card__header { padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; gap: var(--sp-2); }
  .card__title  { font-size: var(--fs-md); }
  .card__body   { padding: var(--sp-3) var(--sp-4); }

  /* KV-list: collapse the 130px label column. Label sits above its value
     so long values (large qty, dates, etc.) get the full row width. */
  .kv-list {
    grid-template-columns: 1fr;
    gap: 2px var(--sp-2);
  }
  .kv-list .kv-key {
    margin-top: var(--sp-2);
  }
  .kv-list .kv-key:first-child { margin-top: 0; }

  /* Inputs: ≥16px font-size so iOS Safari doesn't zoom on focus. */
  .input, .textarea, .select { font-size: 16px; }
  .input--sm { font-size: var(--fs-sm); }

  /* Filters wrap properly. Make each filter field grow/shrink within a row. */
  .filters .field { flex: 1 1 140px; min-width: 0; }
  .filters .input, .filters .select { min-width: 0; }

  /* Toolbar wraps; search no longer caps narrow */
  .toolbar__search { min-width: 0; max-width: 100%; }
  .toolbar__group { width: 100%; }
  .toolbar__group .select { flex: 1 1 0; min-width: 0; }

  /* Modal turns into a bottom sheet. Footer buttons stack full-width. */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-overlay.open { display: flex; }
  .modal,
  .modal.modal--md,
  .modal.modal--lg {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90vh;
  }
  .modal__header { padding: var(--sp-4) var(--sp-5) var(--sp-2); }
  .modal__body   { padding: 0 var(--sp-5) var(--sp-4); }
  .modal__footer {
    flex-direction: column-reverse;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-5) var(--sp-4);
  }
  .modal__footer .btn { width: 100%; justify-content: center; }
  .modal__footer--space-between { flex-direction: column-reverse; }

  /* Empty state padding */
  .empty { padding: var(--sp-8) var(--sp-4); }
}

/* ─── QTY HEALTH ──────────────────────────────────────────────────────── */
/* Color helpers used across every page that renders a quantity. */
.qty-ok   { color: var(--color-success-fg); font-weight: var(--fw-semibold); }
.qty-warn { color: var(--color-warning-fg); font-weight: var(--fw-semibold); }
.qty-low  { color: var(--color-danger-fg);  font-weight: var(--fw-semibold); }

/* ─── TOAST ───────────────────────────────────────────────────────────── */
/* Single toast() function shared by every page. The host #toast is a fixed
   container at bottom-right; each emitted .toast slides in. */
#toast {
  position: fixed;
  bottom: var(--sp-4);
  right: var(--sp-4);
  z-index: var(--z-toast);
  display: flex; flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}
#toast .toast {
  pointer-events: auto;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  box-shadow: var(--shadow-lg);
  animation: toast-slide-in var(--dur-normal) var(--ease-out);
  max-width: 360px;
  background: var(--ink-800); color: #fff;
}
.toast-success { background: var(--success-700); color: #fff; }
.toast-error   { background: var(--danger-700);  color: #fff; }
.toast-info    { background: var(--info-700);    color: #fff; }
@keyframes toast-slide-in {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@media (max-width: 640px) {
  #toast { left: var(--sp-3); right: var(--sp-3); }
  #toast .toast { max-width: 100%; }
}

/* ─── ADJUST MODAL CHROME ─────────────────────────────────────────────── */
/* Inline styles for the markup injected by adjust-modal.js. Pages may also
   embed this markup directly (legacy detail pages). */
.adj-preview {
  background: var(--color-bg-sunken);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-md);
  text-align: center;
}
.adj-preview-empty { color: var(--color-fg-muted); font-style: italic; }
.adj-preview-bad {
  background: var(--color-danger-bg);
  color: var(--color-danger-fg);
  border-color: var(--danger-100);
}
.adj-delta-pill {
  display: inline-block;
  margin-left: var(--sp-2);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-pill);
  background: var(--color-bg-surface);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.adj-summary {
  text-align: center;
  padding: var(--sp-4);
  background: var(--color-bg-sunken);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-4);
}
.adj-summary-name {
  font-size: var(--fs-sm);
  color: var(--color-fg-muted);
  margin-bottom: var(--sp-2);
}
.adj-summary-change {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 28px; font-weight: var(--fw-bold);
  margin-bottom: var(--sp-1);
}
.adj-summary-change .adj-arrow { color: var(--color-fg-muted); margin: 0 var(--sp-3); }
.adj-summary-delta { font-family: var(--font-mono); font-size: var(--fs-md); }

/* ─── MODAL OPEN/CLOSE TOGGLE ─────────────────────────────────────────── */
/* The design's components.css renders .modal-overlay as display:flex
   unconditionally — it assumes JS appends the markup to the DOM when the
   modal opens. Our JS instead toggles an .open class on a permanently-mounted
   overlay (so we can preserve form state across opens). Default the overlay
   to hidden and only show it when the .open class is present. */
.modal-overlay { display: none; }
.modal-overlay.open { display: flex; }

/* ─── KV LIST ─────────────────────────────────────────────────────────── */
/* Two-column key/value layout used by the adjust modal review step. */
.kv-list {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: var(--sp-1) var(--sp-3);
  font-size: var(--fs-md);
}
.kv-list .kv-key {
  color: var(--color-fg-muted);
  font-weight: var(--fw-medium);
  font-size: var(--fs-sm);
}
