/*
 * Parts Tracker — Industry Design System
 *
 * Palette: steel-blue accent on a light technical ground.
 * Typography: Barlow Condensed (headings) + Barlow (body) via Google Fonts.
 * Shape language: square-cornered, hairline-bordered, blueprint registration marks.
 * All colours, shadows, and spacing through CSS custom properties — never hard-code.
 */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;500;600;700&family=Barlow:wght@400;500;600&display=swap');

/* =========================================================================
   Tokens
   ========================================================================= */

:root {
  /* Ground & surfaces */
  --color-bg:       #f2f2f3;
  --color-surface:  #e9e9ea;
  --color-surface2: #dfdfe0;

  /* Text */
  --color-text:        #1d1f20;
  --color-text-muted:  color-mix(in srgb, #1d1f20 55%, transparent);
  --color-text-subtle: color-mix(in srgb, #1d1f20 35%, transparent);

  /* Accent — steel blue */
  --color-accent:      #5980a6;
  --color-accent-100:  oklch(0.95 0.025 230);
  --color-accent-200:  oklch(0.88 0.05  230);
  --color-accent-300:  oklch(0.79 0.08  230);
  --color-accent-400:  oklch(0.69 0.10  230);
  --color-accent-500:  oklch(0.58 0.12  230);
  --color-accent-600:  oklch(0.50 0.12  230);
  --color-accent-700:  oklch(0.42 0.11  230);
  --color-accent-800:  oklch(0.33 0.09  230);
  --color-accent-900:  #1d2d3d;

  /* Borders */
  --color-border:  color-mix(in srgb, #1d1f20 18%, transparent);
  --color-border2: color-mix(in srgb, #1d1f20 28%, transparent);

  /* Status colours */
  --color-registered-fg: #5a5f63;
  --color-registered-bg: #ebebec;
  --color-registered-bd: #c6c8ca;

  --color-verify-fg: #2c455d;
  --color-verify-bg: #eef6ff;
  --color-verify-bd: #94bce3;

  --color-check-fg:  oklch(0.44 0.10 150);
  --color-check-bg:  oklch(0.96 0.03  150);
  --color-check-bd:  oklch(0.75 0.10  150);

  --color-defect-fg: oklch(0.48 0.17 25);
  --color-defect-bg: oklch(0.96 0.03  25);
  --color-defect-bd: oklch(0.75 0.14  25);

  /* Sync status */
  --color-sync-pending-fg: oklch(0.50 0.14 60);
  --color-sync-pending-bg: oklch(0.96 0.04 60);
  --color-sync-pending-bd: oklch(0.78 0.12 60);

  /* Shadows */
  --shadow-sm: 0 1px 3px color-mix(in srgb, #1d1f20 12%, transparent);
  --shadow-md: 0 2px 8px color-mix(in srgb, #1d1f20 14%, transparent);
  --shadow-lg: 0 4px 20px color-mix(in srgb, #1d1f20 16%, transparent);

  /* Spacing scale (0.85× density) */
  --sp-1: 3.4px;
  --sp-2: 6.8px;
  --sp-3: 10.2px;
  --sp-4: 13.6px;
  --sp-5: 20.4px;
  --sp-6: 27.2px;
  --sp-7: 34px;
  --sp-8: 40.8px;

  /* Radius — blueprint: sharp but not harsh */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 7px;

  /* Typography */
  --font-heading: 'Barlow Condensed', system-ui, sans-serif;
  --font-body:    'Barlow', system-ui, sans-serif;
}

/* =========================================================================
   Reset & base
   ========================================================================= */

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

html {
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body { min-height: 100dvh; }

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, video { max-width: 100%; display: block; }

/* =========================================================================
   Typography
   ========================================================================= */

h1, h2, h3, h4, h5 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { line-height: 1.55; }

.text-muted   { color: var(--color-text-muted); }
.text-subtle  { color: var(--color-text-subtle); }
.text-accent  { color: var(--color-accent); }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.text-lg      { font-size: 1.125rem; }
.font-heading { font-family: var(--font-heading); }
.font-mono    { font-family: 'Courier New', Courier, monospace; }

/* =========================================================================
   Layout shell
   ========================================================================= */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  /* Push below the phone status bar in PWA standalone mode */
  padding: calc(var(--sp-3) + env(safe-area-inset-top, 0px)) var(--sp-5) var(--sp-3);
  background: var(--color-accent-900);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: calc(56px + env(safe-area-inset-top, 0px));
}

.topbar-brand {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  text-transform: uppercase;
  flex: 1;
}

.topbar-brand a { color: inherit; display: inline-flex; align-items: center; }

.topbar-actions { display: flex; align-items: center; gap: var(--sp-3); }

/* Brand wordmark — one SVG (logo-black.svg / logo-white.svg) used in the
   topbar, sidebar and login headers. The SVG has aspect ratio 143:11, so
   sizing by height alone gives a natural width. Inline-block keeps it flowing
   with sibling text (e.g. "/ Customer" on the external login header). */
.brand-logo {
  display: inline-block;
  height: 14px;
  width: auto;
  max-width: 100%;
  vertical-align: middle;
}
.brand-logo-lg { height: 22px; }
@media (max-width: 380px) {
  .brand-logo    { height: 12px; }
  .brand-logo-lg { height: 18px; }
}

/* Bottom nav (mobile primary navigation) */
.bottom-nav {
  display: flex;
  align-items: stretch;
  background: var(--color-accent-900);
  border-top: 1px solid rgba(255,255,255,0.12);
  /* Fixed to viewport bottom — prevents blank gap on short pages in PWA */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  /* Home indicator clearance on iPhone */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--sp-2) var(--sp-2) var(--sp-3);
  color: rgba(255,255,255,0.55);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: none;
  min-height: 56px;
  transition: color 0.15s;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
  color: #fff;
  text-decoration: none;
}

.bottom-nav-item.active {
  background: rgba(255,255,255,0.08);
}

.bottom-nav-item svg { width: 22px; height: 22px; }

/* Main content — bottom padding clears the fixed bottom nav */
.content {
  flex: 1;
  padding: var(--sp-5);
  padding-bottom: calc(var(--sp-5) + 56px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.content-wide {
  max-width: 960px;
}

/* =========================================================================
   Blueprint frame card
   ========================================================================= */

.blueprint {
  position: relative;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
}

.corner {
  position: absolute;
  width: 10px;
  height: 10px;
}

.corner::before,
.corner::after {
  content: '';
  position: absolute;
  background: var(--color-border2);
}

.corner::before { width: 1px; height: 100%; left: 50%; transform: translateX(-50%); }
.corner::after  { height: 1px; width: 100%; top: 50%; transform: translateY(-50%); }

.corner.tl { top: -5px; left: -5px; }
.corner.tr { top: -5px; right: -5px; }
.corner.bl { bottom: -5px; left: -5px; }
.corner.br { bottom: -5px; right: -5px; }

/* =========================================================================
   Cards
   ========================================================================= */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: var(--sp-4); }
.card-kicker  { font-family: var(--font-heading); font-size: 0.7rem; font-weight: 600;
                letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-text-muted); }
.card-title   { font-family: var(--font-heading); font-size: 1.25rem; font-weight: 600; margin-top: var(--sp-1); }
.card-body    { margin-top: var(--sp-3); }
.card-meta    { font-size: 0.8rem; color: var(--color-text-muted); margin-top: var(--sp-3); }
.card-row     { display: flex; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-3); }
.card-actions { display: flex; justify-content: flex-end; gap: var(--sp-2);
                padding-top: var(--sp-3);
                border-top: 1px solid var(--color-border);
                margin-top: var(--sp-3); }

/* Danger zone — the last block on admin-visible detail pages. Muted-red frame
   makes it clearly distinct from normal actions without shouting for
   attention. */
.danger-zone {
  border: 1px solid var(--color-defect-bd);
  background: var(--color-defect-bg);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  margin-top: var(--sp-5);
}
.danger-zone-title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-defect-fg);
  margin-bottom: var(--sp-2);
}
.danger-zone-desc {
  color: var(--color-defect-fg);
  font-size: 0.9rem;
  margin-bottom: var(--sp-4);
  opacity: 0.9;
}

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.card-link:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent-300);
  text-decoration: none;
}

/* Stat card (admin dashboard) */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  text-align: center;
}

.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--color-accent);
}

.stat-card .stat-label {
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-top: var(--sp-2);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

/* =========================================================================
   Status badges
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-registered {
  color: var(--color-registered-fg);
  background: var(--color-registered-bg);
  border-color: var(--color-registered-bd);
}

.badge-verified {
  color: var(--color-verify-fg);
  background: var(--color-verify-bg);
  border-color: var(--color-verify-bd);
}

.badge-checked {
  color: var(--color-check-fg);
  background: var(--color-check-bg);
  border-color: var(--color-check-bd);
}

.badge-defective {
  color: var(--color-defect-fg);
  background: var(--color-defect-bg);
  border-color: var(--color-defect-bd);
}

.badge-sync-pending {
  color: var(--color-sync-pending-fg);
  background: var(--color-sync-pending-bg);
  border-color: var(--color-sync-pending-bd);
}

.badge-sync-ok {
  color: var(--color-text-muted);
  background: var(--color-surface2);
  border-color: var(--color-border);
}

/* Dot indicator */
.badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 48px;   /* Glove-friendly tap target */
  transition: background 0.12s, box-shadow 0.12s, transform 0.08s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); text-decoration: none; }
.btn:hover  { text-decoration: none; }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent-700);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--color-accent-600); color: #fff; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border2);
}
.btn-secondary:hover { background: var(--color-surface2); }

.btn-danger {
  background: var(--color-defect-bg);
  color: var(--color-defect-fg);
  border-color: var(--color-defect-bd);
}
.btn-danger:hover { background: oklch(0.90 0.06 25); color: var(--color-defect-fg); }

.btn-success {
  background: var(--color-check-bg);
  color: var(--color-check-fg);
  border-color: var(--color-check-bd);
}
.btn-success:hover { background: oklch(0.90 0.06 150); color: var(--color-check-fg); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}
.btn-ghost:hover { background: var(--color-surface); color: var(--color-text); }

.btn-icon {
  padding: 10px;
  min-width: 48px;
  width: 48px;
  height: 48px;
}

.btn-block { width: 100%; }

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  min-height: 34px;
  letter-spacing: 0.04em;
}
.btn-sm svg { width: 14px; height: 14px; }

.btn-lg {
  padding: 16px 28px;
  font-size: 1.1rem;
  min-height: 56px;
}

/* =========================================================================
   Forms & inputs
   ========================================================================= */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field + .field { margin-top: var(--sp-4); }

label {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.input {
  width: 100%;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--color-border2);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--color-text);
  min-height: 48px;
  transition: border-color 0.12s, box-shadow 0.12s;
  appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 20%, transparent);
}

.input::placeholder { color: var(--color-text-subtle); }

.input-error {
  border-color: var(--color-defect-bd) !important;
}

select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235a5f63' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

textarea.input { resize: vertical; min-height: 96px; }

/* File input */
.file-input-wrap {
  position: relative;
  border: 2px dashed var(--color-border2);
  border-radius: var(--radius-md);
  padding: var(--sp-6);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.file-input-wrap:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-100);
}
.file-input-wrap input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}

/* Capture tiles — pairs of camera / library actions used on media capture and
   certificate upload. Each tile is a <label> wrapping a single-file <input>
   with a specific accept + capture combination so mobile Safari opens the
   camera directly instead of the file picker. */
.capture-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.capture-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 128px;
  padding: var(--sp-5) var(--sp-3);
  background: var(--color-surface);
  border: 2px dashed var(--color-border2);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.capture-tile:hover,
.capture-tile:focus-within {
  border-color: var(--color-accent);
  background: var(--color-accent-100);
  box-shadow: var(--shadow-sm);
}
/* Selected state — a file is picked but not yet submitted. Signals the user
   that the picked file is committed and can still be swapped by tapping again. */
.capture-tile.has-file {
  border-style: solid;
  border-color: var(--color-accent);
  background: var(--color-accent-100);
}
.capture-tile.has-file .capture-tile-title::before {
  content: "✓ ";
  color: var(--color-accent);
}
/* Hide the input visually but keep it reachable — iOS Safari reliably triggers
   the picker when the wrapping <label> is tapped, whereas tapping an
   opacity:0 input directly is a known WebKit quirk. */
.capture-tile input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
/* Ensure taps on inner content (SVG icon, text) reach the wrapping label
   instead of being absorbed by children — some iOS versions swallow taps
   on inline SVG. */
.capture-tile > *:not(input) { pointer-events: none; }
.capture-tile-title {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}
.capture-tile-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Secondary "attach from library" action — full-width row, smaller footprint. */
.capture-secondary {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 48px;
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border2);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.capture-secondary:hover,
.capture-secondary:focus-within {
  border-color: var(--color-accent);
  background: var(--color-accent-100);
  color: var(--color-text);
}
.capture-secondary input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
.capture-secondary > *:not(input) { pointer-events: none; }
.capture-secondary svg { color: var(--color-accent); flex-shrink: 0; }

/* Segmented control — language switcher */
.seg {
  display: inline-flex;
  border: 1px solid var(--color-border2);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface);
}

.seg-opt {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
  min-height: 40px;
}

.seg-opt.active,
.seg-opt[aria-pressed="true"] {
  background: var(--color-accent);
  color: #fff;
}

/* Language switcher on dark bg */
.seg-dark {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
}

.seg-dark .seg-opt { color: rgba(255,255,255,0.6); }
.seg-dark .seg-opt.active { background: var(--color-accent); color: #fff; }

/* =========================================================================
   Number keypad
   ========================================================================= */

.keypad-display {
  background: #fff;
  border: 1px solid var(--color-border2);
  border-radius: var(--radius-md);
  padding: var(--sp-4) var(--sp-5);
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent-900);
  margin-bottom: var(--sp-4);
}

.keypad-display.empty { color: var(--color-text-subtle); }
.keypad-display.error { border-color: var(--color-defect-bd); background: var(--color-defect-bg); color: var(--color-defect-fg); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
  max-width: 320px;
  margin: 0 auto;
}

.keypad-letters {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: var(--sp-3);
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.08s, transform 0.06s;
}

.key:active { background: var(--color-surface2); transform: scale(0.95); }
.key.key-alpha { font-size: 0.9rem; letter-spacing: 0.06em; flex-direction: column; gap: 1px; }
.key.key-alpha .key-num { font-size: 1.4rem; line-height: 1; }
.key.key-alpha .key-letters { font-size: 0.55rem; color: var(--color-text-muted); letter-spacing: 0.08em; }
.key.key-clear { background: var(--color-defect-bg); color: var(--color-defect-fg); border-color: var(--color-defect-bd); }
.key.key-enter { background: var(--color-accent); color: #fff; border-color: var(--color-accent-700); font-size: 1rem; letter-spacing: 0.05em; }

/* =========================================================================
   Serial ID hero display
   ========================================================================= */

.serial-hero {
  background: var(--color-accent-900);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--sp-5) var(--sp-6);
  text-align: center;
}

.serial-hero .serial-label {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
  margin-bottom: var(--sp-2);
}

.serial-hero .serial-id {
  font-family: var(--font-heading);
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1.1;
}

.serial-hero .serial-sub {
  margin-top: var(--sp-3);
  font-size: 0.78rem;
  color: rgba(255,255,255,0.65);
  letter-spacing: 0.04em;
}
.serial-hero .serial-sub .font-mono {
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.06em;
}

/* =========================================================================
   Media thumbnails grid
   ========================================================================= */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.media-thumb {
  aspect-ratio: 1;
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

.media-thumb img,
.media-thumb video {
  width: 100%; height: 100%;
  object-fit: cover;
}

.media-thumb .media-type-icon {
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(0,0,0,0.55);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 0.65rem;
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Remove-media button pinned to the top-right of a thumbnail. Sized for a
   glove tap (36px hit area) while staying visually compact on small tiles. */
.media-delete-form {
  position: absolute;
  top: 4px;
  right: 4px;
  margin: 0;
}
.media-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.media-delete:hover,
.media-delete:focus {
  background: var(--color-defect-fg);
  outline: none;
}
.media-delete:active { transform: scale(0.94); }

/* Verify-step "type instead" collapsible fallback. Kept low-key so the primary
   camera capture stays the obvious choice; expands to reveal a text input. */
.verify-fallback {
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.verify-fallback > summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  list-style: none;
  min-height: 32px;
  display: flex;
  align-items: center;
}
.verify-fallback > summary::-webkit-details-marker { display: none; }
.verify-fallback > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: var(--sp-2);
  transition: transform 0.15s;
  color: var(--color-text-muted);
}
.verify-fallback[open] > summary::before { transform: rotate(90deg); }
.verify-fallback[open] > summary { color: var(--color-text); }

/* Verification-photo badge on media thumbnails — replaces the neutral "PHOTO"
   label with an accent-colored "VERIFIED" pill so the laser-mark proof is
   obvious in the media grid. */
.media-thumb .media-type-icon.is-verification {
  background: var(--color-verify-fg);
  color: #fff;
}

/* =========================================================================
   Lightbox — fullscreen photo/video preview with optional delete action.

   Triggered by any element carrying data-lightbox="1"; JS (in layout.html)
   reads data-src, data-type ("photo"|"video"), and — when the current user
   is allowed to delete — data-delete-url + data-delete-confirm + data-next.
   Closes on Esc, on backdrop click, or via the × button.
   ========================================================================= */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.94);
  display: none;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.lightbox-overlay.is-open { display: flex; }

/* Lock underlying page scroll while the lightbox is open. Prevents iOS
   inertial scrolling from dragging the page behind the fixed overlay. */
body.lightbox-locked {
  overflow: hidden;
  touch-action: none;
}

.lightbox-stage {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-media {
  max-width: min(96vw, 1400px);
  max-height: calc(100vh - 140px);
  object-fit: contain;
  border-radius: var(--radius-md);
  background: #000;
  display: block;
}

/* Toolbar with close (right) + optional delete (left). Fixed to the top
   so tall images don't push the controls off-screen. Container itself is
   pointer-transparent so backdrop clicks pass through to the overlay. */
.lightbox-toolbar {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  pointer-events: none;
  z-index: 1;
}
.lightbox-toolbar > * { pointer-events: auto; }

.lightbox-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: #fff;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s, transform 0.05s;
}
.lightbox-btn:hover  { background: rgba(255, 255, 255, 0.24); }
.lightbox-btn:active { transform: scale(0.97); }
.lightbox-btn.is-danger { background: var(--color-defect-fg); }
.lightbox-btn.is-danger:hover {
  background: color-mix(in srgb, var(--color-defect-fg) 82%, white 18%);
}
.lightbox-btn.is-icon { padding: 10px; width: 44px; }

/* Click zone inside a capture-step thumbnail. Sits below the corner ×
   delete button and the type badge (both use position: absolute with a
   higher stacking context), and covers the full tile so tapping the
   photo opens the preview. */
.media-thumb-open {
  display: block;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
  color: inherit;
  text-decoration: none;
}
.media-thumb-open img,
.media-thumb-open video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* =========================================================================
   Audit / timeline
   ========================================================================= */

.audit-timeline { margin-top: var(--sp-4); }

.audit-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
}

.audit-item:last-child { border-bottom: none; }

.audit-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--color-accent-300);
  border: 2px solid var(--color-accent);
  flex-shrink: 0;
  margin-top: 4px;
}

.audit-body { flex: 1; }
.audit-action { font-weight: 600; color: var(--color-text); }
.audit-by     { color: var(--color-text-muted); font-family: var(--font-heading); font-size: 0.8rem; letter-spacing: 0.04em; }
.audit-time   { font-size: 0.75rem; color: var(--color-text-subtle); margin-top: 2px; }

/* =========================================================================
   Alert / flash messages
   ========================================================================= */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: 0.9rem;
  margin-bottom: var(--sp-4);
}

.alert-success {
  background: var(--color-check-bg);
  color: var(--color-check-fg);
  border-color: var(--color-check-bd);
}

.alert-danger {
  background: var(--color-defect-bg);
  color: var(--color-defect-fg);
  border-color: var(--color-defect-bd);
}

.alert-warning {
  background: var(--color-sync-pending-bg);
  color: var(--color-sync-pending-fg);
  border-color: var(--color-sync-pending-bd);
}

.alert-info {
  background: var(--color-verify-bg);
  color: var(--color-verify-fg);
  border-color: var(--color-verify-bd);
}

/* =========================================================================
   Tables
   ========================================================================= */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: var(--color-surface);
  white-space: nowrap;
}

.table tbody tr:hover { background: var(--color-surface); }
.table tbody tr:last-child td { border-bottom: none; }

/* =========================================================================
   Section header
   ========================================================================= */

.section-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.section-header h2 { flex: 1; }

/* =========================================================================
   Part type / series choice grid
   ========================================================================= */

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--sp-4);
}

.choice-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 0.95rem;
  transition: border-color 0.12s, background 0.12s;
  min-height: 96px;
}

.choice-item:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-100);
}

.choice-item.selected {
  border-color: var(--color-accent);
  background: var(--color-accent-100);
  color: var(--color-accent-800);
}

.choice-item .choice-code {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-accent);
}

/* =========================================================================
   Step wizard indicator
   ========================================================================= */

.step-indicator {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: var(--sp-5);
}

.step-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-size: 0.85rem; font-weight: 700;
  flex-shrink: 0;
  transition: background 0.15s;
}

.step-dot.done    { background: var(--color-accent);     color: #fff; }
.step-dot.active  { background: var(--color-accent-900); color: #fff; }
.step-dot.pending { background: var(--color-surface2);   color: var(--color-text-muted); border: 1px solid var(--color-border); }

.step-line {
  flex: 1;
  height: 2px;
  background: var(--color-border);
}
.step-line.done { background: var(--color-accent-300); }

/* =========================================================================
   Certificate badge (auto-inherited)
   ========================================================================= */

.cert-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--color-verify-bg);
  border: 1px solid var(--color-verify-bd);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--color-verify-fg);
}

.cert-badge svg { flex-shrink: 0; width: 18px; height: 18px; }
.cert-badge .cert-inherited-label {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

/* =========================================================================
   Login pages
   ========================================================================= */

/* Internal login — light */
.login-internal-page {
  min-height: 100dvh;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--sp-5) + env(safe-area-inset-top, 0px)) var(--sp-5) calc(var(--sp-8) + env(safe-area-inset-bottom, 20px));
}

.login-header {
  width: 100%;
  max-width: 400px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-5);
  margin-bottom: var(--sp-6);
  padding-top: var(--sp-5);
}

.login-brand {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent-900);
  min-width: 0;
  flex-shrink: 1;
}
.login-brand .brand-logo,
.login-brand .brand-logo-lg { max-width: 100%; }

.login-form-wrap {
  width: 100%;
  max-width: 400px;
}

/* External login — dark navy */
.login-external-page {
  min-height: 100dvh;
  background: var(--color-accent-900);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--sp-5) + env(safe-area-inset-top, 0px)) var(--sp-5) calc(var(--sp-8) + env(safe-area-inset-bottom, 0px));
  color: #fff;
}

.login-external-page .login-brand { color: #fff; }
.login-external-page .login-brand span { opacity: 0.6; }

.login-external-page .input {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: #fff;
}
.login-external-page .input::placeholder { color: rgba(255,255,255,0.35); }
.login-external-page .input:focus {
  border-color: var(--color-accent-300);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 30%, transparent);
}
.login-external-page label { color: rgba(255,255,255,0.6); }

.login-external-page .btn-primary { background: var(--color-accent); border-color: var(--color-accent-400); }
.login-external-page a { color: var(--color-accent-300); }

/* =========================================================================
   Sync indicator in topbar
   ========================================================================= */

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sync-badge.pending {
  background: var(--color-sync-pending-bg);
  color: var(--color-sync-pending-fg);
  border: 1px solid var(--color-sync-pending-bd);
}

.sync-badge.synced {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.5);
}

/* =========================================================================
   Pagination
   ========================================================================= */

.pagination {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
  flex-wrap: wrap;
}

.page-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--color-border2);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-size: 0.875rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: background 0.12s;
}

.page-link:hover { background: var(--color-surface2); text-decoration: none; color: var(--color-text); }
.page-link.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent-700); }
.page-link.disabled { opacity: 0.4; pointer-events: none; }

/* =========================================================================
   Utility classes
   ========================================================================= */

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.gap-5  { gap: var(--sp-5); }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.mt-2 { margin-top: var(--sp-2); }
.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); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }

.text-center { text-align: center; }
.w-full      { width: 100%; }
.hidden      { display: none !important; }

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--sp-5) 0;
}

.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-5);
  color: var(--color-text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto var(--sp-4); opacity: 0.4; }

/* =========================================================================
   Touch feedback
   ========================================================================= */

.tap:active { transform: scale(0.98); }

/* =========================================================================
   Responsive adjustments
   ========================================================================= */

@media (min-width: 600px) {
  .content { padding: var(--sp-6); }
  .choice-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .keypad { max-width: 360px; }
}

@media (min-width: 768px) {
  /* Tablet: show sidebar instead of bottom nav */
  .app-shell { flex-direction: row; }
  .sidebar {
    width: 220px;
    min-height: 100dvh;
    background: var(--color-accent-900);
    display: flex;
    flex-direction: column;
    padding: var(--sp-5) 0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100dvh;
    overflow-y: auto;
  }

  .sidebar-brand {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    padding: 0 var(--sp-5) var(--sp-5);
    border-bottom: 1px solid rgba(255,255,255,0.10);
    margin-bottom: var(--sp-4);
  }

  .sidebar-nav { display: flex; flex-direction: column; flex: 1; }

  .sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    color: rgba(255,255,255,0.6);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-decoration: none;
    transition: color 0.12s, background 0.12s;
    min-height: 44px;
  }

  .sidebar-item:hover,
  .sidebar-item.active {
    color: #fff;
    background: rgba(255,255,255,0.08);
    text-decoration: none;
  }

  .sidebar-item svg { width: 18px; height: 18px; flex-shrink: 0; }

  .sidebar-footer {
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid rgba(255,255,255,0.10);
    margin-top: auto;
  }

  .main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

  /* Sidebar carries the brand on tablet/desktop — hide the topbar copy so
     the logo isn't shown twice on the same screen. */
  .topbar-brand { display: none; }

  .bottom-nav { display: none; }

  /* On tablet, content doesn't need bottom nav clearance */
  .content {
    padding-bottom: var(--sp-5);
  }
  .topbar { position: static; }
  .content { max-width: none; }
  .content-wide { max-width: none; }
}
