:root {
  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-surface-alt: #f2f2f2;
  --color-text: #111111;
  --color-text-muted: #7a7a7a;
  --color-accent: #d7ff2f;
  --color-accent-ink: #111111;
  --color-dark: #171717;
  --color-dark-alt: #1b1b1b;
  --color-border: #e7e7e7;
  --color-disabled: #cfcfcf;
  --color-success: #2e7d32;
  --color-warning: #b58105;
  --color-error: #b3261e;
  --radius-card: 22px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  /* Room for the floating bottom nav so content never sits under it. */
  padding-bottom: 96px;
}

body.no-bottom-nav {
  padding-bottom: 0;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-card);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(17, 17, 17, 0.04);
}

h1, h2, h3 {
  margin: 0 0 12px;
  font-weight: 700;
}

h1 {
  font-size: 34px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 22px;
  font-weight: 600;
}

a {
  color: var(--color-text);
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text-muted);
}

input, textarea, select {
  display: block;
  width: 100%;
  font-size: 16px;
  padding: 13px 14px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

textarea {
  min-height: 96px;
  font-family: inherit;
}

input[type="date"] {
  /* Native date controls report an intrinsic content width that can
     exceed a narrow 100%-width box on some mobile browsers, pushing the
     field past the card's edge — visibly wider than a sibling text input
     even though both are width:100%. Two lighter fixes (min-width:0,
     tighter padding) didn't fully stop it, so also strip the native
     appearance — WebKit's own chrome around the control is what was
     ignoring the box, not just its padding. */
  min-width: 0;
  max-width: 100%;
  padding-right: 8px;
  -webkit-appearance: none;
  appearance: none;
}

.type-toggle {
  display: flex;
  gap: 8px;
}

.type-option {
  flex: 1;
  display: block;
  margin: 0;
  padding: 13px 14px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  cursor: pointer;
}

.type-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.type-option:has(input:checked) {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  border-color: var(--color-accent);
}

.box-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.box-photo-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.box-photo-thumb {
  width: 100%;
  /* Follows .box-guide so the review grid shows the shot roughly as framed
     instead of cropping its sides away. */
  aspect-ratio: 4 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--color-border);
  background: var(--color-surface-alt);
}

.box-photo-thumb.box-photo-ok {
  border-color: var(--color-success);
  border-width: 3px;
}

.box-photo-thumb.box-photo-fail {
  border-color: var(--color-error);
}

.box-photo-manual-input {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  text-align: center;
  text-transform: uppercase;
}

.box-photo-manual-input.box-photo-ok {
  border-color: var(--color-success);
}

.box-photo-manual-input.box-photo-fail {
  border-color: var(--color-error);
}

#recognize-status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--color-warning);
  text-align: center;
}

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  transition: transform 150ms ease-out, opacity 150ms ease-out;
}

.btn:hover {
  opacity: 0.9;
}

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

.btn.secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-row {
  /* Plain block flow, not position:sticky — this screen has no bottom
     nav to dock against, and sticking it 96px above a viewport bottom
     that has nothing reserved for it made it overlap the card above. */
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 24px;
}

.msg {
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 12px;
  font-size: 15px;
}

.msg.error {
  background: #fbeceb;
  color: var(--color-error);
}

.msg.success {
  background: #eaf5ea;
  color: var(--color-success);
}

.msg.warning {
  background: #fbf1de;
  color: var(--color-warning);
}

/* ── Rights-generation progress ── */
.rights-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
}

.spinner {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.rights-url-box {
  background: var(--color-surface-alt);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 14px 0 20px;
  font-size: 14px;
  word-break: break-all;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 4px;
  max-width: 480px;
  margin: 0 auto;
}

.topbar strong {
  font-size: 15px;
}

.topbar form {
  margin: 0;
}

.topbar .btn-exit {
  width: auto;
  min-height: auto;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--color-text-muted);
  background: none;
  border: none;
}

/* ── Contextual exit action — the one navigation control every
   secondary screen gets, in place of a back arrow/breadcrumb. ── */
.btn-exit {
  display: inline-block;
  background: none;
  border: none;
  padding: 10px 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  text-decoration: none;
}

/* ── Login welcome ── */
.welcome-block {
  text-align: center;
  padding: 44px 24px 8px;
}

.welcome-logo {
  width: 76px;
  height: 76px;
  border-radius: 20px;
  animation: welcome-pop 700ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.welcome-title {
  margin: 20px 0 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.3;
  animation: welcome-rise 600ms ease-out 150ms both;
}

.welcome-brand {
  display: inline-block;
  background: linear-gradient(90deg, var(--color-text), var(--color-accent), var(--color-text));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: welcome-shine 3.5s linear infinite;
}

@keyframes welcome-pop {
  0% {
    opacity: 0;
    transform: scale(0.6) translateY(-12px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes welcome-rise {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes welcome-shine {
  to {
    background-position: -200% center;
  }
}

.back-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--color-surface-alt);
}

.back-arrow svg {
  width: 20px;
  height: 20px;
  stroke: var(--color-text);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Home screen ── */
.home-top-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  margin-bottom: 8px;
  animation: home-float 3.2s ease-in-out infinite;
}

@keyframes home-float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.home-footer {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

.home-footer-brand {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
}

.home-footer-desc {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.home-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px 24px;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}

.avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
}

.home-greeting {
  margin: 20px 0 32px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.home-page .btn {
  max-width: 340px;
}

.home-logout {
  margin-top: 28px;
}

.home-logout .btn-exit {
  font-size: 13px;
  color: var(--color-disabled);
}

/* ── History screen ── */
.history-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-date-group {
  margin: 24px 0 10px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.history-card-title {
  font-weight: 600;
  font-size: 17px;
  margin-bottom: 2px;
}

.history-card-meta {
  color: var(--color-text-muted);
  font-size: 14px;
}

.type-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
}

.history-card-count {
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
}

/* ── Floating bottom nav ── */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: var(--color-dark);
  border-radius: var(--radius-pill);
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 10;
}

.bottom-nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  color: #8a8a8a;
  text-decoration: none;
}

.bottom-nav-item svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bottom-nav-item.active {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

/* Scanner screen — the one screen that stays dark/immersive on purpose:
   fullscreen viewfinder, light controls overlaid on top. */
.scan-page {
  /* Fixed + inset, not height:100vh — on iOS Safari 100vh includes the
     area behind the collapsing address bar, which pushed the bottom
     controls off-screen and made the page scrollable. */
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
}

#reader {
  position: absolute;
  inset: 0;
}

#reader video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#reader.scan-flash-success {
  outline: 6px solid #22c55e;
  outline-offset: -6px;
  animation: scan-ring-pulse 0.4s ease-out;
}

#reader.scan-flash-duplicate {
  outline: 6px solid #eab308;
  outline-offset: -6px;
  animation: scan-ring-pulse 0.4s ease-out;
}

@keyframes scan-ring-pulse {
  0% {
    outline-offset: -6px;
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.5);
  }
  40% {
    outline-offset: -12px;
    box-shadow: 0 0 0 14px rgba(255, 255, 255, 0);
  }
  100% {
    outline-offset: -6px;
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.scan-message {
  position: absolute;
  top: 32%;
  left: 0;
  right: 0;
  z-index: 6;
  text-align: center;
  pointer-events: none;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.02em;
  -webkit-text-stroke: 3px rgba(0, 0, 0, 0.85);
  paint-order: stroke fill;
  opacity: 0;
  transform: scale(0.6);
}

.scan-message.scan-message-show {
  animation: scan-message-pop 1.1s ease-out;
}

.scan-message-success {
  color: #22c55e;
}

.scan-message-duplicate {
  color: #eab308;
}

@keyframes scan-message-pop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  18% {
    opacity: 1;
    transform: scale(1.15);
  }
  32% {
    transform: scale(1);
  }
  78% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

.scan-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.65), transparent);
}

.scan-hud .btn-exit {
  color: rgba(255, 255, 255, 0.8);
}

.scan-side-controls {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.btn-torch,
.btn-zoom {
  width: 40px;
  height: 40px;
  flex: none;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  color: #ffffff;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-torch {
  font-size: 18px;
}

.btn-zoom {
  font-size: 13px;
  font-weight: 600;
}

.btn-torch.active,
.btn-zoom.active {
  background: var(--color-accent);
  color: var(--color-accent-ink);
}

.zoom-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scan-count {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.4);
}

.scan-count-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.scan-count-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.scan-recent {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  padding: 0 16px;
  text-align: center;
  color: #ffffff;
  font-size: 14px;
  opacity: 0.9;
}

.camera-debug {
  position: absolute;
  top: 96px;
  left: 8px;
  right: 8px;
  max-height: 40vh;
  overflow-y: auto;
  margin: 0;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-accent);
  background: rgba(0, 0, 0, 0.75);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
  z-index: 20;
}

#box-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.box-guide-wrap {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  z-index: 3;
}

.box-guide-hint {
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.box-guide {
  width: 78vw;
  /* Half the height of the original 2/1 box. The code is a single line, so
     a taller frame only fed the barcode and neighbouring label text into
     Tesseract, which hurt recognition more than it helped with aiming. */
  aspect-ratio: 4 / 1;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  /* Spotlight effect: one giant shadow dims everything outside this box
     without a separate full-screen overlay element. */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
}

.box-guide-flash-success {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), 0 0 0 4px var(--color-accent) inset;
}

.box-guide-flash-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), 0 0 0 4px var(--color-error) inset;
}

.box-guide-flash-blank {
  border-color: var(--color-warning);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), 0 0 0 4px var(--color-warning) inset;
}

.btn-shutter {
  align-self: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.9);
  background: #ffffff;
  padding: 0;
}

.btn-shutter:active {
  transform: scale(0.94);
}

.scan-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
}

/* ══════════════════════════════════════════════════════════════════
   Desktop
   The app is mobile-first and stays that way below 900px. Everything
   here either styles markup that only desktop shows (top nav, table
   header, lightbox) or, inside the media query, re-lays-out the two
   screens people use from the office: the history list and an order.
   ══════════════════════════════════════════════════════════════════ */

/* Hidden on mobile — the floating bottom nav is the navigation there. */
.desktop-nav {
  display: none;
}

/* ── Serial/box-code list ── */
.serials-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.serials-header label {
  margin: 0;
}

.serials-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-mini {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 6px 15px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn-mini:hover {
  background: var(--color-border);
}

.serial-list {
  margin: 0;
  padding-left: 30px;
  max-height: 240px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}

.serial-list li {
  padding: 3px 0;
  font-size: 15px;
}

.serial-list li::marker {
  color: var(--color-text-muted);
  font-size: 12px;
}

/* ── History rows ──
   The row wrapper holds the clickable card plus its delete button, so
   the button isn't nested inside the anchor. Sorting reorders these
   wrappers, which is why the data-* attributes live there. */
.history-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 20px;
}

.history-row .history-card {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.history-col-main {
  flex: 1;
  min-width: 0;
}

.history-card-title,
.history-card-meta {
  display: block;
}

/* Columns the mobile card folds into its meta line. */
.history-col-date,
.history-col-creator,
.history-col-type,
.history-head {
  display: none;
}

/* Once a column is sorted the per-date headings no longer line up with
   the rows beneath them, so they come out of the list entirely. */
#history-list.sorted .history-date-group {
  display: none;
}

.history-delete {
  flex: none;
  width: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
}

.history-delete svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-delete:hover {
  color: var(--color-error);
  border-color: var(--color-error);
}

.history-delete:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Photo lightbox ── */
.box-photo-thumb {
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: rgba(0, 0, 0, 0.85);
  cursor: zoom-out;
}

/* Beats the display:flex above — without this the overlay would stay
   laid out while [hidden] is set. */
.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

/* ── Home: WAVIoT support ── */
.home-support {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

.home-support-title {
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 700;
}

.home-support-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
}

/* The phone is the scanner and already has history in its bottom nav, so
   the history link and the desktop blurb only turn up on wide screens. */
.home-history-link,
.home-desc-desktop {
  display: none;
}

@media (min-width: 900px) {
  body {
    /* No floating bottom nav to clear at this width. */
    padding-bottom: 40px;
  }

  .bottom-nav {
    display: none;
  }

  /* ── Top navigation ── */
  .desktop-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 64px;
    padding: 0 32px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
  }

  .desktop-nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    text-decoration: none;
  }

  .desktop-nav-brand img {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .desktop-nav-links {
    display: flex;
    gap: 6px;
    margin-right: auto;
  }

  .desktop-nav-links a {
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-decoration: none;
  }

  .desktop-nav-links a:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
  }

  .desktop-nav-links a.active {
    background: var(--color-accent);
    color: var(--color-accent-ink);
  }

  .desktop-nav-user {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
    color: var(--color-text-muted);
  }

  .desktop-nav-user form {
    margin: 0;
  }

  /* ── Shared layout ── */
  .container-wide {
    max-width: 1180px;
    padding: 28px 32px 48px;
  }

  h1 {
    font-size: 30px;
  }

  /* ── History as a table ──
     One column track shared by the header row and every card below it,
     so the two stay aligned. */
  #history-list,
  .history-head {
    --history-cols: 116px minmax(0, 1fr) 190px 130px 90px;
  }

  .history-filters {
    flex-direction: row;
    align-items: flex-end;
    gap: 16px;
  }

  .history-filters > div {
    flex: 1;
  }

  .history-filters .btn {
    flex: none;
    width: auto;
    min-height: 46px;
    padding: 0 26px;
  }

  .history-head {
    display: grid;
    grid-template-columns: var(--history-cols);
    gap: 16px;
    padding: 0 22px;
    /* Matches the delete button (46px) plus the row's gap (8px) so the
       header's last column sits over the count, not over the button. */
    margin: 0 54px 8px 0;
  }

  .history-sort {
    padding: 6px 0;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    cursor: pointer;
  }

  .history-sort:hover,
  .history-sort.active {
    color: var(--color-text);
  }

  .history-sort.active::after {
    content: " ↓";
  }

  .history-sort.active[data-dir="asc"]::after {
    content: " ↑";
  }

  .history-sort.num {
    text-align: right;
  }

  .history-row {
    margin-bottom: 8px;
  }

  .history-row .history-card {
    display: grid;
    grid-template-columns: var(--history-cols);
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    border-radius: 16px;
  }

  .history-row .history-card:hover {
    box-shadow: 0 2px 12px rgba(17, 17, 17, 0.1);
  }

  .history-col-date,
  .history-col-creator,
  .history-col-type {
    display: block;
  }

  .history-col-date {
    font-size: 14px;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
  }

  .history-col-creator {
    font-size: 14px;
    color: var(--color-text-muted);
  }

  /* The date group headings and the stacked meta line are the mobile
     way of showing what now has real columns. */
  .history-date-group,
  .history-card-meta {
    display: none;
  }

  .history-card-title {
    margin-bottom: 0;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .type-badge {
    margin-left: 0;
  }

  .history-card-count {
    font-size: 18px;
    text-align: right;
  }

  .history-delete {
    border-radius: 16px;
  }

  /* ── Order detail ──
     DOM order is the mobile one (info → content → actions); on desktop
     the two side blocks move into a right-hand column. */
  .order-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas:
      "main info"
      "main actions";
    align-items: start;
    column-gap: 24px;
  }

  .order-info {
    grid-area: info;
  }

  .order-main {
    grid-area: main;
  }

  .order-actions {
    grid-area: actions;
  }

  .order-actions .btn-row {
    margin-top: 0;
  }

  .serial-list {
    max-height: 60vh;
  }

  .box-photo-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  /* ── Home ──
     Nothing at a desk should start a scan, so both routes into the camera
     go away; "Выйти" is dropped as well because the top nav already has it. */
  .home-cta,
  .btn-rescan,
  .home-logout,
  .home-desc-mobile {
    display: none;
  }

  .home-history-link,
  .home-desc-desktop {
    display: block;
  }

  .home-page {
    max-width: 620px;
    padding-top: 40px;
  }
}
