/* ── Carton Cache — Main Stylesheet ─────────────────────────────────────────── */

/* Design tokens */
:root {
  --color-bg:         #f5f5f0;
  --color-surface:    #ffffff;
  --color-border:     #ddddd8;
  --color-text:       #1a1a1e;
  --color-text-muted: #6b6b6e;
  --color-primary:    #2563eb;
  --color-primary-fg: #ffffff;
  --color-danger:     #dc2626;
  --color-danger-fg:  #ffffff;
  --color-warning:    #d97706;
  --color-success:    #16a34a;

  --condition-new:    #2563eb;
  --condition-good:   #16a34a;
  --condition-fair:   #d97706;
  --condition-poor:   #dc2626;

  --radius:    0.5rem;
  --radius-sm: 0.25rem;
  --space-1:   0.25rem;
  --space-2:   0.5rem;
  --space-3:   0.75rem;
  --space-4:   1rem;
  --space-6:   1.5rem;
  --space-8:   2rem;
  --space-12:  3rem;

  --font-body: system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, monospace;

  /* Surface tints — overridden in dark mode */
  --alert-error-bg:       #fef2f2;
  --alert-error-border:   #fecaca;
  --alert-warning-bg:     #fffbeb;
  --alert-warning-border: #fde68a;
  --badge-new-bg:         #dbeafe;
  --badge-good-bg:        #dcfce7;
  --badge-fair-bg:        #fef3c7;
  --badge-poor-bg:        #fee2e2;
  --card-low-bg:          #fffbeb;
  --card-low-border:      var(--color-warning);
  --quick-action-border:  rgba(0, 0, 0, 0.18);
}

/* ── Dark mode tokens ─────────────────────────────────────────────────────── */
/* System: OS dark + no explicit override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:             #111113;
    --color-surface:        #1c1c21;
    --color-border:         #2e2e36;
    --color-text:           #e8e8ec;
    --color-text-muted:     #8888a0;
    --condition-new:        #60a5fa;
    --condition-good:       #4ade80;
    --condition-fair:       #fbbf24;
    --condition-poor:       #f87171;
    --alert-error-bg:       #2c1515;
    --alert-error-border:   #5c2020;
    --alert-warning-bg:     #2c2010;
    --alert-warning-border: #5c3e10;
    --badge-new-bg:         #162040;
    --badge-good-bg:        #102818;
    --badge-fair-bg:        #261c06;
    --badge-poor-bg:        #2c1010;
    --card-low-bg:          #241908;
    --quick-action-border:  rgba(255, 255, 255, 0.15);
  }
}

[data-theme="dark"] {
  --color-bg:             #111113;
  --color-surface:        #1c1c21;
  --color-border:         #2e2e36;
  --color-text:           #e8e8ec;
  --color-text-muted:     #8888a0;
  --condition-new:        #60a5fa;
  --condition-good:       #4ade80;
  --condition-fair:       #fbbf24;
  --condition-poor:       #f87171;
  --alert-error-bg:       #2c1515;
  --alert-error-border:   #5c2020;
  --alert-warning-bg:     #2c2010;
  --alert-warning-border: #5c3e10;
  --badge-new-bg:         #162040;
  --badge-good-bg:        #102818;
  --badge-fair-bg:        #261c06;
  --badge-poor-bg:        #2c1010;
  --card-low-bg:          #241908;
  --quick-action-border:  rgba(255, 255, 255, 0.15);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  overscroll-behavior: contain;
  -webkit-text-size-adjust: 100%;
}

img, svg { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.2; }

/* ── Nav height token — keeps main content clear of the fixed bar ─────────── */
:root {
  --nav-h: 6.5rem;   /* mobile: two rows (brand+tools, nav) for authenticated */
}
@media (min-width: 640px) {
  :root { --nav-h: 3.75rem; }
}

/* Public pages (welcome, login, register) — header is always single row */
body.has-nav:not(.has-app-nav) {
  --nav-h: 3.75rem;
}

body.has-nav {
  padding-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
}

/* Jumping to an #anchor (e.g. back to an edited carton row) stops below the
   fixed header instead of underneath it. */
:target {
  scroll-margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + var(--space-4));
}

/* ── Header — mobile-first grid ───────────────────────────────────────────── */
/* Public (unauthenticated) header is always single-row */
body:not(.has-app-nav) .site-header {
  grid-template-areas: "brand logout";
  grid-template-columns: 1fr auto;
}

.site-header {
  display: grid;
  grid-template-areas: "brand logout" "nav nav";
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;

  @media (min-width: 640px) {
    grid-template-areas: "brand nav logout";
    grid-template-columns: auto 1fr auto;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-6);
    padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  }
}

.brand-group {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;

  &::before {
    content: '';
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    background: var(--color-primary);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
  }
}

.brand-org {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  padding-left: var(--space-2);
  border-left: 1px solid var(--color-border);
}

/* ── Nav — horizontal scroll on mobile ───────────────────────────────────── */
.site-nav {
  grid-area: nav;
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: var(--space-1) 0;

  &::-webkit-scrollbar { display: none; }

  & a {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text);
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;

    &:hover { background: var(--color-bg); }

    &[aria-current="page"] {
      background: var(--color-primary);
      color: var(--color-primary-fg);
    }
  }

  @media (min-width: 640px) {
    flex-wrap: wrap;
    overflow-x: visible;
    flex: 1;
  }
}

/* ── Public nav (sign in) ────────────────────────────────────────────────── */
.site-nav--public {
  grid-area: logout;
  flex-wrap: nowrap;
  overflow-x: visible;
  flex: 0;
  padding: 0;
  gap: var(--space-2);
  align-items: center;
  margin-left: auto;
  justify-content: flex-end;
}

/* ── Header tools (QR + avatar) ───────────────────────────────────────────── */
.header-tools {
  grid-area: logout;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ── Avatar & dropdown ────────────────────────────────────────────────────── */
avatar-menu {
  position: relative;
  display: flex;
  align-items: center;
}

/* Remove native <details> marker from <summary> */
summary.avatar { list-style: none; }
summary.avatar::-webkit-details-marker { display: none; }

.avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: var(--avatar-bg, var(--color-primary));
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.15s, opacity 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;

  &:hover { opacity: 0.85; }

  details[open] > & { outline-color: var(--color-primary); }
}

.avatar--md {
  width: 2.5rem;
  height: 2.5rem;
  font-size: 0.8rem;
  cursor: default;
  pointer-events: none;
}

/* ── 8 avatar color options ───────────────────────────────────────────────── */
:is(.avatar, .color-option__swatch)[data-color="color-1"] { --avatar-bg: #2563eb; }
:is(.avatar, .color-option__swatch)[data-color="color-2"] { --avatar-bg: #16a34a; }
:is(.avatar, .color-option__swatch)[data-color="color-3"] { --avatar-bg: #d97706; }
:is(.avatar, .color-option__swatch)[data-color="color-4"] { --avatar-bg: #dc2626; }
:is(.avatar, .color-option__swatch)[data-color="color-5"] { --avatar-bg: #7c3aed; }
:is(.avatar, .color-option__swatch)[data-color="color-6"] { --avatar-bg: #0891b2; }
:is(.avatar, .color-option__swatch)[data-color="color-7"] { --avatar-bg: #be185d; }
:is(.avatar, .color-option__swatch)[data-color="color-8"] { --avatar-bg: #059669; }

/* ── Dropdown panel ───────────────────────────────────────────────────────── */
@keyframes dropdown-enter {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.avatar-dropdown {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 16rem;
  max-width: calc(100vw - var(--space-6));
  max-height: calc(100vh - var(--nav-h) - var(--space-4));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: calc(var(--radius) * 1.5);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 16px 40px rgba(0,0,0,0.14);
  z-index: 200;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: dropdown-enter 0.15s ease both;
}

.avatar-dropdown__header {
  padding: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.avatar-dropdown__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.avatar-dropdown__name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-dropdown__role {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  text-transform: capitalize;
  letter-spacing: 0.04em;
}

.avatar-dropdown__nav {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.avatar-dropdown__nav a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--color-text);
  font-size: 0.875rem;
  transition: background 0.1s, color 0.1s;
}

.avatar-dropdown__nav a:hover {
  background: var(--color-bg);
  color: var(--color-primary);
}

.avatar-dropdown__nav svg {
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: color 0.1s;
}

.avatar-dropdown__nav a:hover svg {
  color: var(--color-primary);
}

.avatar-dropdown__theme {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.avatar-dropdown__theme svg { flex-shrink: 0; }

.avatar-dropdown__signout {
  padding: var(--space-2);
}

.avatar-dropdown__signout form { width: 100%; }

.avatar-dropdown__signout-btn {
  width: 100%;
  background: transparent;
  color: var(--color-danger);
  font-size: 0.875rem;
  justify-content: center;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}

.avatar-dropdown__signout-btn:hover {
  background: var(--alert-error-bg);
  border-color: var(--alert-error-border);
}

/* Make theme-selector transparent to flex layout so the select stretches */
theme-selector { display: contents; }

.theme-select {
  font-size: 0.85rem;
  min-height: 2.25rem;
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  flex: 1;
}

/* ── Profile page ─────────────────────────────────────────────────────────── */
.profile-preview {
  display: flex;
  justify-content: center;
  padding: var(--space-4) 0;
}

.avatar--preview {
  width: 4rem;
  height: 4rem;
  font-size: 1.25rem;
}

.profile-email {
  display: block;
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--color-text-muted);
  min-height: 2.75rem;
  line-height: calc(2.75rem - 2px);
}

/* ── Color picker ─────────────────────────────────────────────────────────── */
.color-picker {
  border: none;
  padding: 0;
  margin: 0;

  legend {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: var(--space-2);
  }
}

.color-options {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.color-option {
  position: relative;
  cursor: pointer;

  &__radio {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    min-height: 0;
    pointer-events: none;
  }

  &__swatch {
    display: block;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--avatar-bg, #ccc);
    border: 3px solid transparent;
    outline: 2px solid transparent;
    transition: outline-color 0.12s, transform 0.1s;
    cursor: pointer;
  }

  &:has(:checked) &__swatch,
  &__radio:focus-visible + &__swatch {
    outline-color: var(--color-text);
    outline-offset: 2px;
    transform: scale(1.1);
  }
}

.password-fields {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ── Main & Footer ────────────────────────────────────────────────────────── */
.site-main {
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-3);
  container-type: inline-size;
  container-name: main;

  @media (min-width: 640px) {
    padding: var(--space-6) var(--space-4);
  }
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  padding: var(--space-6) var(--space-4);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.site-footer__inner {
  max-width: 72rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.site-footer__brand {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--color-text);
  margin-right: auto;
}

.site-footer__links {
  display: flex;
  gap: var(--space-4);
}

.site-footer__links a {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.1s;
}

.site-footer__links a:hover { color: var(--color-text); }

.site-footer__copy { color: var(--color-text-muted); }

.site-footer__copy a {
  color: var(--color-text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.1s;
}

.site-footer__copy a:hover { color: var(--color-text); }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: var(--space-4); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.action-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
:is(.btn, button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.12s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;

  &:hover { filter: brightness(0.93); }
  &:active { filter: brightness(0.87); transform: translateY(1px); }
  &:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
}

.btn--primary,
button[type="submit"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-fg);
}

.btn--danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: #fff;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: var(--space-1);
}

/* Text-like controls only: checkboxes and radios keep their native size. */
:is(input:not([type="checkbox"], [type="radio"]), select, textarea) {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;

  &:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
    border-color: var(--color-primary);
  }
}

.form-group { display: flex; flex-direction: column; gap: var(--space-1); }

/* Remove browser-default border/padding from fieldsets used as form-groups */
fieldset.form-group {
  border: none;
  padding: 0;
  margin: 0;
}

/* A titled group of fields within a longer form (e.g. the carton type form).
   Sections after the first are separated by a rule above their title. */
.form-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;

  /* Floated, the legend is laid out as an ordinary flex item instead of
     being drawn over the fieldset's top border. */
  & > legend {
    float: left;
    width: 100%;
    padding: 0;
    margin: 0;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
  }

  /* Sub-groups (e.g. the three dimension inputs) are titled like a label. */
  & fieldset.form-group > legend {
    padding: 0;
    margin-bottom: var(--space-1);
    font-size: 0.9rem;
    font-weight: 600;
  }

  /* Keep hints directly under their input (Kelp adds a bottom margin to
     inputs that aren't a :last-child). */
  & .form-group > :is(input, select, textarea) { margin-block-end: 0; }
}

.stack > .form-section + .form-section,
.stack > input[type="hidden"] + .form-section {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-6);
}

/* A checkbox with its label text beside it, and its hint aligned under the text. */
.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: 0;
  cursor: pointer;

  & input {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--color-primary);
  }

  & + small { padding-left: calc(1.1rem + var(--space-2)); }
}

/* Two fields side by side on wider screens, stacked on phones. */
.form-row {
  display: grid;
  gap: var(--space-4);

  @container main (min-width: 480px) {
    grid-template-columns: 1fr 1fr;
  }
}

/* Full-width submit on standalone transaction forms */
.form-card > form > button[type="submit"] {
  width: 100%;
  min-height: 3rem;
  font-size: 1rem;
  font-weight: 600;
  margin-top: var(--space-2);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;

  & label { margin-bottom: 0; }
}

.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);

  @container main (min-width: 480px) {
    padding: var(--space-6);
    max-width: 36rem;
  }
}

/* ── Form helpers ─────────────────────────────────────────────────────────── */
.input-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;

  /* Kelp gives inputs that aren't :last-child a bottom margin, which would
     throw off centering against the button that follows them in the row. */
  & input,
  & select { flex: 1; min-width: 0; margin-block-end: 0; }
}

/* Let the Scan button itself be the flex item, so it lines up with the input
   instead of sitting in a wrapper box with a line box's extra descender space. */
:is(carton-scanner, barcode-scanner) { display: contents; }

/* −/+ buttons around a number input. Hidden until the element upgrades, so
   without JS it's just the plain input. */
qty-stepper {
  & input { text-align: center; font-variant-numeric: tabular-nums; }
  &:not(:defined) .qty-stepper__btn { display: none; }
}

.qty-stepper__btn {
  min-width: 2.75rem;
  padding-inline: var(--space-3);
  font-size: 1.15rem;
  font-weight: 600;
  touch-action: manipulation; /* no double-tap zoom when tapping + quickly */
}

.dims-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

/* ── Welcome page ─────────────────────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-4) var(--space-12);
  animation: welcome-fade 0.5s ease both;
}

@keyframes welcome-fade {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome__hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  text-align: center;
  max-width: 38rem;
  padding: var(--space-8) var(--space-4);
}

.welcome__hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 30%,
    rgba(37, 99, 235, 0.08) 0%,
    transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.welcome__hero > * { position: relative; z-index: 1; }

.welcome__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 99px;
  padding: 0.25rem var(--space-3);
  margin: 0;
}

.welcome__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.welcome__icon {
  width: 3.5rem;
  height: 3.5rem;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(37, 99, 235, 0.25));
}

.welcome__title {
  font-size: clamp(2.25rem, 7vw, 3.75rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1;
  margin: 0;
  background: linear-gradient(135deg, var(--color-text) 40%, var(--color-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome__tagline {
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--color-text-muted);
  margin: 0;
  max-width: 30rem;
}

.welcome__actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: var(--space-2);
}

.welcome__cta {
  min-width: 9rem;
  justify-content: center;
  font-size: 1rem;
  padding: 0.75rem var(--space-6);
}

.welcome__features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--space-4);
  width: 100%;
  max-width: 54rem;
}

.welcome__feature {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: box-shadow 0.15s, transform 0.15s;
}

.welcome__feature:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.welcome__feature h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.welcome__feature p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.welcome__feature-badge {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  background: rgba(37, 99, 235, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-primary);
}

.welcome__feature-badge svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* ── Auth ─────────────────────────────────────────────────────────────────── */
.auth-card {
  background: var(--color-surface);
  padding: var(--space-6) var(--space-4);

  @container main (min-width: 480px) {
    max-width: 24rem;
    margin: var(--space-12) auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-8);
  }
}

.auth-sub    { color: var(--color-text-muted); margin-top: 0; }
.auth-switch { margin-top: var(--space-4); text-align: center; font-size: 0.9rem; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 0.9rem;

  &--error {
    background: var(--alert-error-bg);
    color: var(--color-danger);
    border: 1px solid var(--alert-error-border);
  }

  &--warning {
    background: var(--alert-warning-bg);
    color: var(--color-warning);
    border: 1px solid var(--alert-warning-border);
  }

  &--success {
    background: var(--badge-good-bg);
    color: var(--color-success);
    border: 1px solid var(--badge-good-bg);
  }
}

/* ── Quick actions ────────────────────────────────────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 5.5rem;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 2px solid var(--quick-action-border);
  box-shadow:
    inset 0 -4px 0 rgba(0, 0, 0, 0.28),
    inset 0  1px 0 rgba(255, 255, 255, 0.22);
  text-decoration: none;
  text-align: center;
  gap: var(--space-1);
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.12s, transform 0.1s, box-shadow 0.1s;

  &:hover  { filter: brightness(0.94); }
  &:active {
    transform: translateY(3px);
    box-shadow:
      inset 0 2px 4px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }

  /* Receive — blue, white fg: 5.2:1 contrast ✓ */
  &--in {
    background: var(--color-primary);
    color: var(--color-primary-fg);
  }

  /* Consume — red, white fg: 4.8:1 contrast ✓ (passes AA for all text sizes) */
  &--out {
    background: var(--color-danger);
    color: var(--color-danger-fg);
  }
}

.quick-action__icon {
  width: 1.5rem;
  height: 1.5rem;
}

.quick-action__verb {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  color: inherit;
}

.quick-action__hint {
  font-size: 0.8125rem;
  font-weight: 500;
  color: inherit;
}

/* ── Dashboard ────────────────────────────────────────────────────────────── */
.inventory-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-4);
}

.inventory-heading {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin: 0;
}

/* Two-option segmented control; the current option is filled. */
.sort-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.8125rem;

  & a {
    padding: var(--space-1) var(--space-3);
    color: var(--color-text-muted);
    text-decoration: none;
  }
  & a + a { border-left: 1px solid var(--color-border); }
  & a:hover { color: var(--color-text); }
  & a[aria-current] {
    background: var(--color-primary);
    color: var(--color-primary-fg);
  }
}

.location-block {
  margin-bottom: var(--space-8);
  container-type: inline-size;
  container-name: location;
}

/* A sublocation's section follows its parent's, indented. */
.location-block--sub {
  padding-inline-start: var(--space-4);
  border-inline-start: 2px solid var(--color-border);
}

.location-title {
  margin-bottom: var(--space-4);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.8rem;
  font-weight: 700;
}

/* ── Sublocations (stacks, shelves, bins inside a location) ─────────────── */
.location-row--sub td:first-child { padding-inline-start: var(--space-8); }
.location-row__in { margin-inline-end: var(--space-1); color: var(--color-text-muted); }

/* "Office ›" above a sublocation's page title. */
.location-crumb {
  margin: 0 0 var(--space-1);
  font-size: 0.85rem;
  color: var(--color-text-muted);

  & a { color: inherit; }
}

.sublocations {
  margin-bottom: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  overflow: hidden;
}

.sublocations__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);

  & h2 {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
  }
}

.sublocations__empty {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.sublocations__list {
  list-style: none;
  margin: 0;
  padding: 0;

  & li {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);

    &:last-child { border-bottom: none; }
  }

  & a { font-weight: 600; }
}

.sublocations__total {
  margin-inline-start: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.move-location {
  margin-bottom: var(--space-6);

  & summary { cursor: pointer; font-weight: 600; }
  &[open] summary { margin-bottom: var(--space-4); }
}

/* ── Transfer several: checklist of a location's stock ───────────────────── */
.transfer-lots {
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;

  & legend {
    padding: 0 var(--space-2);
    margin-inline-start: var(--space-3);
    font-size: 0.9rem;
    font-weight: 600;
  }
}

.transfer-lots__all {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  font-weight: 600;
}

.transfer-lots__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.transfer-lot {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);

  &:last-child { border-bottom: none; }
  &:has(input[name="lot"]:checked) { background: color-mix(in srgb, var(--color-primary) 6%, transparent); }

  & input[type="checkbox"] { width: 1.15rem; height: 1.15rem; margin: 0; }
}

.transfer-lot__name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-2);
  margin: 0;
  font-weight: 400;
  cursor: pointer;
  min-width: 0;
}

.transfer-lot__code { font-family: var(--font-mono); font-weight: 700; }

.transfer-lot__qty {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;

  & input { width: 4.5rem; min-height: 2.25rem; padding-block: var(--space-1); text-align: right; }
  & small { color: var(--color-text-muted); }
}

@media (max-width: 480px) {
  .transfer-lot {
    grid-template-columns: auto minmax(0, 1fr) auto;
    & .transfer-lot__qty { grid-column: 2 / -1; justify-self: end; }
  }
}

/* ── Dashboard stock list ─────────────────────────────────────────────────── */
/* One row per carton type at a location: label code (or size) and name, a chip per condition
   in stock, and the total. Sorted by length, then width, then height, by the route. */
.stock-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  overflow: hidden;
}

.stock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "main conditions total";
  align-items: center;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  border-left: 3px solid transparent;
  scroll-margin-top: calc(var(--nav-h) + var(--space-4));
  transition: background-color 0.2s ease;

  &:last-child { border-bottom: none; }

  &.stock-row--low {
    border-left-color: var(--card-low-border);
    background: var(--card-low-bg);
  }

  &:target { animation: row-flash 2s ease-out; }

  @container location (max-width: 520px) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "main       total"
      "conditions total";
  }
}

.stock-row__main {
  grid-area: main;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-3);
  min-width: 0;
}

/* The row's lead: the label code printed on the box, else the size. */
.stock-row__lead {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;

  & small { font-weight: 400; color: var(--color-text-muted); }
  &.stock-row__lead--none { font-weight: 400; color: var(--color-text-muted); }
}

.stock-row__label { font-family: var(--font-mono); }

.stock-row__print {
  display: inline-grid;
  place-items: center;
  /* Comfortable tap target without growing the row. */
  margin-block: calc(-1 * var(--space-2));
  margin-inline-start: var(--space-1);
  padding: var(--space-2);
  vertical-align: middle;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);

  & svg { width: 1.1em; height: 1.1em; }
  &:hover, &:focus-visible { color: var(--color-primary); }
}

.stock-row__name {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

.stock-row__flag {
  margin-inline-start: var(--space-1);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-warning);
}

.stock-row__conditions {
  grid-area: conditions;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* Condition chip: reuses the .condition--* colors, with the count in bold. */
.stock-chip {
  gap: 0.35em;
  font-variant-numeric: tabular-nums;

  & strong { font-weight: 800; }
}

.stock-row__out {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-warning);
}

.stock-row__total {
  grid-area: total;
  min-width: 2ch;
  text-align: right;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);

  .stock-row--low & { color: var(--color-warning); }
}

/* ── Dashboard low-stock summary ──────────────────────────────────────────── */
.low-stock {
  margin-bottom: var(--space-8);
  border: 1px solid var(--alert-warning-border);
  border-left: 3px solid var(--color-warning);
  border-radius: var(--radius);
  background: var(--alert-warning-bg);
  overflow: hidden;
}

.low-stock__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) var(--space-4) var(--space-2);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-warning);
}

.low-stock__count {
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--color-warning);
  color: #fff;
  font-size: 0.75rem;
  letter-spacing: 0;
}

.low-stock__list {
  list-style: none;
  margin: 0;
  padding: 0 0 var(--space-2);

  & a {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 var(--space-3);
    padding: var(--space-2) var(--space-4);
    color: inherit;
    text-decoration: none;
    transition: background-color 0.15s ease;

    &:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
    @media (hover: hover) {
      &:hover { background: color-mix(in srgb, var(--color-warning) 10%, transparent); }
    }
  }
}

.low-stock__name { font-weight: 600; }
.low-stock__where { font-size: 0.85rem; color: var(--color-text-muted); }
.low-stock__qty {
  margin-inline-start: auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-warning);

  & small { font-weight: 400; color: var(--color-text-muted); }
}

.lot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);

  @container location (min-width: 480px) {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

.lot-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.15s, transform 0.1s;

  &:hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
  }
}

.lot-card__name   { font-weight: 600; font-size: 0.95rem; }
.lot-card__sku    { font-size: 0.75rem; color: var(--color-text-muted); font-family: var(--font-mono); }

/* The × between L, W and H in HTML dimension text. Plain-text contexts
   (<option>s, textContent) use thin spaces instead; see formatDims(). */
/* Opacity rather than a color so it stays a step lighter than whatever text
   it sits in (already-muted card text or normal table text), in both themes. */
.dim-x { margin-inline: 0.15em; opacity: 0.75; }
.lot-card__qty    { font-size: 2.25rem; font-weight: 800; line-height: 1; color: var(--color-primary); }

/* ── Condition badges ─────────────────────────────────────────────────────── */
:is(.condition--new, .condition--good, .condition--fair, .condition--poor) {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.condition--new  { background: var(--badge-new-bg);  color: var(--condition-new); }
.condition--good { background: var(--badge-good-bg); color: var(--condition-good); }
.condition--fair { background: var(--badge-fair-bg); color: var(--condition-fair); }
.condition--poor { background: var(--badge-poor-bg); color: var(--condition-poor); }

/* A view toggle above a list, e.g. "Show archived (2)" on carton types. */
.list-filter {
  display: flex;
  justify-content: flex-end;
  margin-block: 0 var(--space-2);
}

/* Briefly highlight the row just returned to (e.g. after saving it). */
:is(tr:target > td, .carton-item:target) { animation: row-flash 2s ease-out; }

@keyframes row-flash {
  from { background: color-mix(in srgb, var(--color-primary) 18%, transparent); }
  to   { background: transparent; }
}

/* Neutral status tag, e.g. "Archived" / "One-time use" on carton types. */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-8);
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap {
  container-type: inline-size;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

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

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

  & th {
    font-weight: 600;
    background: var(--color-bg);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
  }

  & tbody tr {
    transition: background 0.1s;
    &:last-child td { border-bottom: none; }
    &:hover { background: var(--color-bg); }
  }
}

/* ── Tables: stacked-card layout at narrow container widths ──────────────── */
@container (max-width: 480px) {
  .table-wrap {
    overflow-x: visible;
    background: transparent;
    border: none;
    border-radius: 0;
  }

  .table-wrap table {
    display: block;

    & thead {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }

    & tbody {
      display: block;
    }

    & tbody tr {
      display: block;
      background: var(--color-surface);
      border: 1px solid var(--color-border);
      border-radius: var(--radius);
      margin-bottom: var(--space-3);
      padding: var(--space-2) var(--space-4);
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);

      &:last-child { margin-bottom: 0; }
      &:last-child td { border-bottom: 1px solid var(--color-border); }
      &:hover { background: var(--color-surface); }
    }

    & td {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-3);
      padding: var(--space-2) 0;
      text-align: right;
      overflow-wrap: anywhere;

      &:last-child { border-bottom: none; }
    }

    & td[data-label]::before {
      content: attr(data-label);
      flex-shrink: 0;
      text-align: left;
      font-weight: 600;
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--color-text-muted);
    }

    & td.table-cell--actions {
      justify-content: flex-end;
      padding-top: var(--space-3);

      & .action-row {
        width: 100%;
        justify-content: flex-end;
      }
    }
  }
}

/* ── Carton type list ─────────────────────────────────────────────────────── */
/* One row per carton type: details on the left, cost and actions on the right;
   at narrow widths details take the full width with cost + actions below. */
.carton-list {
  container-type: inline-size;
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  overflow: hidden;
}

.carton-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "main cost actions";
  align-items: center;
  gap: var(--space-2) var(--space-6);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  scroll-margin-top: calc(var(--nav-h) + var(--space-4));
  transition: background-color 0.2s ease;

  &:last-child { border-bottom: none; }

  @media (hover: hover) {
    &:hover { background: color-mix(in srgb, var(--color-bg) 55%, var(--color-surface)); }
  }

  &.carton-item--archived :is(.carton-item__main, .carton-item__cost) { opacity: 0.6; }

  @container (max-width: 560px) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: var(--space-3);

    & .carton-item__main { flex-basis: 100%; }
    & .carton-item__cost small.each { display: none; }
    & .carton-item__actions { margin-inline-start: auto; }
  }
}

.carton-item__main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.carton-item__name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.carton-item__dims {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--space-3);
  margin: 0;
}

.carton-item__dims-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.carton-item__dims-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.carton-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;

  & div { display: flex; align-items: baseline; gap: var(--space-1); }
  & dt { color: var(--color-text-muted); }
  & dd { margin: 0; }
  & code { font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }
}

.carton-item__notes {
  margin: var(--space-1) 0 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Secondary info (printed size, codes, notes): one truncated line until opened. */
.carton-item__more {
  min-width: 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);

  & summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    list-style: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;

    &::-webkit-details-marker { display: none; }
    &::after {
      content: "";
      flex-shrink: 0;
      width: 0.4em;
      height: 0.4em;
      border-right: 1.5px solid currentColor;
      border-bottom: 1.5px solid currentColor;
      transform: translateY(-0.15em) rotate(45deg);
      transition: transform 0.15s ease;
    }
    &:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
    @media (hover: hover) {
      &:hover { color: var(--color-text); }
    }
  }

  &[open] summary::after { transform: translateY(0.1em) rotate(-135deg); }

  & .carton-item__preview {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  & .carton-item__hide { display: none; }
  &[open] .carton-item__preview { display: none; }
  &[open] .carton-item__hide { display: inline; }

  & .carton-item__meta { margin-top: var(--space-1); }
}

.carton-item__cost {
  grid-area: cost;
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;

  & small { font-weight: 400; color: var(--color-text-muted); }
}

.carton-item__actions {
  grid-area: actions;
  justify-content: flex-end;
  gap: var(--space-2);

  & form { margin: 0; }
  /* Small outlined buttons; also beats the primary fill submit buttons get by default. */
  & .btn {
    min-height: 2.25rem;
    padding-inline: var(--space-3);
    border-color: var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.08s;

    /* Soft tint instead of the global brightness() hover, which dims the whole button. */
    &:hover, &:active { filter: none; }
    @media (hover: hover) {
      &:hover {
        background: color-mix(in srgb, var(--color-text) 5%, var(--color-surface));
        border-color: color-mix(in srgb, var(--color-text) 25%, var(--color-border));
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
      }
    }
  }
  & .btn-ghost--danger {
    color: var(--color-danger);
    border-color: color-mix(in srgb, var(--color-danger) 45%, var(--color-border));

    @media (hover: hover) {
      &:hover {
        background: color-mix(in srgb, var(--color-danger) 8%, var(--color-surface));
        border-color: var(--color-danger);
      }
    }
  }
}

/* ── Icon button ──────────────────────────────────────────────────────────── */
.btn--icon {
  min-height: 2.75rem;
  width: 2.75rem;
  padding: 0;
  flex-shrink: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.btn--scan {
  flex-shrink: 0;
  padding-inline: var(--space-3);
  font-size: 0.875rem;
}

/* ── Barcode scanner dialog ───────────────────────────────────────────────── */
dialog.scan-dialog {
  border: none;
  border-radius: var(--radius);
  background: #000;
  color: #fff;
  padding: var(--space-4);
  width: min(90vw, 22rem);

  /* Only apply flex when the dialog is actually open.
     Without [open] scoping, display:flex overrides the UA's
     display:none for closed dialogs and the dialog stays visible. */
  &[open] {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
  }

  &::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
  }

  & form { width: 100%; }

  & button[type="submit"] {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: #fff;
    width: 100%;
  }
}

.scan-viewport {
  position: relative;
  width: min(80vw, 18rem);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;

  & video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
}

.scan-reticle {
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
  pointer-events: none;

  &::before,
  &::after {
    content: '';
    position: absolute;
    width: 1.5rem;
    height: 1.5rem;
    border-color: var(--color-primary);
    border-style: solid;
  }

  &::before {
    top: -2px;
    left: -2px;
    border-width: 3px 0 0 3px;
    border-radius: var(--radius-sm) 0 0 0;
  }

  &::after {
    bottom: -2px;
    right: -2px;
    border-width: 0 3px 3px 0;
    border-radius: 0 0 var(--radius-sm) 0;
  }
}

/* ── Dialog entry animation ──────────────────────────────────────────────── */
@keyframes dialog-enter {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

dialog[open] {
  animation: dialog-enter 0.2s ease-out both;
}

/* ── Quick-create dialog ──────────────────────────────────────────────────── */
.quick-create-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  background: var(--color-surface);
  color: var(--color-text);
  width: min(90vw, 28rem);
  max-height: 90dvh;
  overflow-y: auto;

  &::backdrop {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
  }

  /* The form and its success step are .stack (display: flex), which would
     otherwise override [hidden] when swapping between them. */
  & [hidden] { display: none; }
}

.quick-create-dialog__title {
  margin: 0;
  font-size: 1.1rem;
}

.action-row--end { justify-content: flex-end; }

/* ── Raw scan data disclosure ─────────────────────────────────────────────── */
.scan-raw {
  & summary {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-1);

    &::-webkit-details-marker { display: none; }

    &::before {
      content: '▶';
      font-size: 0.6rem;
      transition: transform 0.15s;
    }
  }

  &[open] summary::before { transform: rotate(90deg); }
}

.scan-raw__value {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  cursor: default;
}

/* ── QR dialog ────────────────────────────────────────────────────────────── */
.qr-dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  background: var(--color-surface);
  color: var(--color-text);
  width: min(90vw, 20rem);

  &::backdrop {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
  }
}

.qr-dialog__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.qr-dialog__label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-align: center;
}

.qr-dialog__code {
  width: 100%;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: var(--space-2);

  & svg {
    width: 100%;
    height: auto;
    display: block;
  }
}

.qr-dialog__url {
  margin: 0;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  text-align: center;
  word-break: break-all;
  max-width: 100%;
}

/* ── Error page ───────────────────────────────────────────────────────────── */
.error-page {
  max-width: 32rem;
  margin: var(--space-12) auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
