/* ---------------------------------------------------------------------------
   The look is borrowed from the thing this app makes: a thermal label. Warm paper
   white, carbon black, one ink. Codes are set in a monospace because they are machine
   data and a person reads them character by character when something has gone wrong.
   Only the accent and the three semantic colours come from the brand file; the grounds
   are fixed, so nobody's brand can make their own text unreadable.
   --------------------------------------------------------------------------- */
:root {
  /* The greys are MIXED FROM THE ACCENT, not hardcoded. A neutral with a slight hue
     bias toward the brand reads as chosen; one biased the other way fights it - a warm
     brown grey under a purple accent looked like two brands in one page.
     Lightness is anchored to white and black, so a brand can shift the hue but can
     never darken its own background into unreadability. */
  --paper: color-mix(in srgb, var(--accent) 4%, #ffffff);
  --card:  #ffffff;
  --ink:   color-mix(in srgb, var(--accent) 14%, #14131c);
  --ink-2: color-mix(in srgb, var(--accent) 22%, #55525f);
  --ink-3: color-mix(in srgb, var(--accent) 16%, #8b8896);
  --rule:  color-mix(in srgb, var(--accent) 13%, #e4e3ea);
  --rule-2: color-mix(in srgb, var(--accent) 7%, #f1f0f5);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,19,28,.06), 0 4px 16px rgba(20,19,28,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: color-mix(in srgb, var(--accent) 9%, #0f0e16);
    --card:  color-mix(in srgb, var(--accent) 11%, #17161f);
    --ink:   color-mix(in srgb, var(--accent) 8%, #f3f2f8);
    --ink-2: color-mix(in srgb, var(--accent) 16%, #b0adbb);
    --ink-3: color-mix(in srgb, var(--accent) 18%, #7d7a89);
    --rule:  color-mix(in srgb, var(--accent) 16%, #2b2936);
    --rule-2: color-mix(in srgb, var(--accent) 12%, #201f2a);
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 4px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "kern" 1;
  /* Room for the home indicator and the notch, so nothing sits under either. */
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;      /* no rubber-banding the whole page on iOS */
}

/* ---------------------------------------------------------------------------
   TOUCH FIRST. Everything hit by a finger is at least 44px, which is Apple's
   figure and roughly the width of an adult fingertip. Below that you miss, and
   missing while holding a bag is how a tool stops being used.
   --------------------------------------------------------------------------- */
@media (pointer: coarse) {
  button, .tap { min-height: 44px; }
  input, select { min-height: 44px; font-size: 16px; }  /* 16px or iOS zooms the page */
  td.tick { min-width: 48px; }
  tbody td { padding-top: .7rem; padding-bottom: .7rem; }
  /* Hover states are a lie on touch: they stick after a tap until you tap elsewhere. */
  tbody tr:hover td { background: inherit; }
  button:hover { filter: none; }
  tbody tr:not(.picked) td.tick:hover::before { content: ""; }
}
.mono, code, .code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-ligatures: none;
}

/* --- masthead ------------------------------------------------------------ */
header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .8rem 1.25rem; background: var(--card);
  border-bottom: 1px solid var(--rule);
}
.wordmark { display: flex; align-items: baseline; gap: .55rem; min-width: 0; }
.wordmark b {
  font-size: 1rem; font-weight: 650; letter-spacing: -.01em; white-space: nowrap;
}
.wordmark .shop {
  font-size: .74rem; color: var(--ink-3); letter-spacing: .04em;
  text-transform: uppercase; white-space: nowrap;
}
header .rule { flex: 1; height: 1px; background: var(--rule); min-width: 1rem; }
header nav { display: flex; gap: .25rem; }
header nav a {
  padding: .3rem .7rem; border-radius: 999px; font-size: .88rem;
  color: var(--ink-2); text-decoration: none;
}
header nav a:hover { background: var(--rule-2); color: var(--ink); }
header nav a[aria-current] { background: var(--accent); color: var(--accent-ink); }
/* Gold is the second brand colour: used as a hairline under the masthead rather than
   as another button, so it reads as trim and never competes with the accent. */
header { border-bottom: 1px solid var(--rule); box-shadow: inset 0 -3px 0 -2px var(--gold); }
.tally { font-size: .78rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* --- layout -------------------------------------------------------------- */
main {
  padding: 1.25rem; display: grid; gap: 1.25rem; align-items: start;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  max-width: 1500px; margin: 0 auto;
}
main.single { grid-template-columns: minmax(0, 1fr); }
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 1.25rem; align-content: start; }

.card {
  background: var(--card); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow);
}
.card > h2 {
  margin: 0 0 .85rem; font-size: .7rem; font-weight: 650; letter-spacing: .11em;
  text-transform: uppercase; color: var(--ink-3);
  display: flex; align-items: center; gap: .6rem;
}
.card > h2::after { content: ""; flex: 1; height: 1px; background: var(--rule-2); }

/* --- controls ------------------------------------------------------------ */
input[type=text], input[type=search], input[type=number], select {
  width: 100%; padding: .68rem .8rem; font-size: 1rem;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 8px;
}
input[type=text]:focus, input[type=search]:focus, input[type=number]:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}
.scanfield {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.2rem; letter-spacing: .04em;
}
button {
  padding: .62rem 1rem; font-size: .92rem; font-weight: 550; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--ink-2); border-color: var(--rule); }
button.ghost:hover { background: var(--rule-2); color: var(--ink); filter: none; }
/* ---------------------------------------------------------------------------
   Each brand colour gets ONE job, so it means something rather than decorating:

     purple  primary action, and the selected state
     gold    the brand mark, and the batch total - the thing being made
     green   will scan
     red     will not scan
     blue    navigation - links and the preview stepper
     pink    structure - the item rows that hold variations

   Sprinkling five colours with no rule is how a page stops being readable; a colour
   that always means the same thing can be read without looking it up.
   --------------------------------------------------------------------------- */

/* Light blue: informational, and deliberately not alarming - undo is a calm offer,
   not a warning. */
.undobar {
  border-color: var(--light-blue);
  background: color-mix(in srgb, var(--light-blue) 22%, var(--card));
  padding: .7rem 1.1rem;
}
.undobar button {
  background: var(--blue); color: #fff;
}

/* Gold on the batch total. It is the count of the thing you are actually making. */
#joblabels { color: var(--gold); }

/* Blue for navigation: links, and the stepper through the batch. */
a { color: var(--blue); }
.stepper button { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 35%, transparent); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* --- data ---------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
  position: sticky; top: 0; background: var(--card); text-align: left;
  font-size: .68rem; font-weight: 650; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3); padding: .4rem .55rem; border-bottom: 1px solid var(--rule);
}
tbody td { padding: .4rem .55rem; border-bottom: 1px solid var(--rule-2); }
tbody tr:hover td { background: var(--rule-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Selected rows. Three signals at once - a tick, an accent bar, a tinted ground - so
   the state survives a glance across the room, a washed-out screen, and colourblindness.
   One of them alone is the kind of subtlety you only notice when it is missing. */
td.tick {
  width: 2rem; text-align: center; cursor: pointer; user-select: none;
  color: var(--accent); font-weight: 700;
}
tbody tr.picked td { background: color-mix(in srgb, var(--accent) 9%, transparent); }
tbody tr.picked td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tbody tr.picked:hover td { background: color-mix(in srgb, var(--accent) 15%, transparent); }
tbody tr.viewing td { outline: 1px solid var(--accent); outline-offset: -1px; }
td.tick::before { content: ""; }
tbody tr:not(.picked) td.tick:hover::before {
  content: "+"; color: var(--ink-3); font-weight: 400;
}
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.muted { color: var(--ink-3); }

/* Item -> variation. The parent row is the thing you recognise; the variations are
   the things that have codes. Disclosure only appears where there is something to
   disclose - an arrow that reveals a single row is a tap that buys nothing. */
tr.group td {
  background: var(--rule-2); font-weight: 600;
  border-top: 1px solid var(--rule); border-bottom: 0;
}
tr.group td.disclose { cursor: pointer; user-select: none; }
tr.group td.disclose .arrow {
  display: inline-block; color: var(--ink-3); font-weight: 400;
  transition: transform .15s ease; width: 1rem;
}
tr.group.open td.disclose .arrow { transform: rotate(90deg); color: var(--accent); }
/* Tri-state: blank, a dash for some, a tick for all - the same three states every
   file manager uses, so it needs no explaining. */
tr.group td.grouptick { cursor: pointer; }
tr.variation td:first-child { padding-left: 1.6rem; }
tr.variation.hidden { display: none; }
/* General, because .hidden used to only work on a table row - putting it on anything
   else silently did nothing, which is the worst kind of CSS bug: the markup reads as
   though it works. Kept after the rule above so both still apply. */
.hidden { display: none !important; }

/* Quantity stepper.
   iOS draws NO spinner on input[type=number] - it opens a keyboard instead - so the
   native control gave an iPad no way at all to increment. These are real buttons,
   44px on touch, which is the documented minimum for a finger. */
.qtyform .step {
  width: 2rem; height: 2rem; padding: 0; flex: 0 0 auto;
  font-size: 1.05rem; line-height: 1; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--paper-2); color: var(--ink-2);
  border: 1px solid var(--rule); border-radius: .5rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;          /* no 300ms wait, no double-tap zoom */
  user-select: none;
}
.qtyform .step:hover  { border-color: var(--accent); color: var(--accent); }
.qtyform .step:active { transform: scale(.94); }
.qtyform input[type=number] {
  width: 3.1rem; padding: .25rem .3rem; text-align: center;
  font-variant-numeric: tabular-nums;
}
/* The native spinners are ~10px tall and sit right next to our own buttons, which is
   two controls doing one job in a space too small for either. */
.qtyform input[type=number] { -moz-appearance: textfield; }
.qtyform input[type=number]::-webkit-outer-spin-button,
.qtyform input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
/* Never wrap. The three parts are one control; stacking them turns "minus, five, plus"
   into a column that is unreadable and doubles the row height. */
.qtyform { flex-wrap: nowrap; white-space: nowrap; }
td.qtycell { width: 1%; white-space: nowrap; }

/* The subtitle only exists where the columns are folded away; on a desktop the columns
   say it all. Declared BEFORE every media query that reveals it, or source order beats
   the override - two equally specific rules, and the last one in the file wins. */
.sub { display: none; font-size: .78rem; line-height: 1.35; margin-top: .1rem; }

@media (pointer: coarse) {
  .qtyform .step { width: 2.75rem; height: 2.75rem; font-size: 1.2rem; }
  /* 16px or iOS zooms the whole page when the field takes focus. */
  .qtyform input[type=number] { width: 3.4rem; font-size: 16px; }

  /* Fold the duplicated columns on ANY touch screen, not just a narrow one.
     An iPad is 820px wide, so it kept all seven columns AND got 44px steppers, and
     the stepper wrapped into a stack two rows tall. Variant, code, price and stock are
     already in the subtitle under the name, so nothing is lost by folding them - and
     finger-sized controls are worth more on a tablet than a repeated column. */
  .col-var, .col-code, .col-price, .col-stock { display: none; }
  .sub { display: block; }
  tbody td { padding: .5rem .45rem; }

  /* Everything you can tap gets a finger-sized target. WCAG 2.2 SC 2.5.5 and Apple's
     HIG both land on 44 CSS pixels, and the top navigation was 31 - on the control
     used more than any other, on the device this is meant for. */
  header nav a {
    min-height: 44px; display: inline-flex; align-items: center;
    padding: .3rem .85rem;
  }
  /* A native checkbox renders about 13px wide. Scaled up rather than replaced, so it
     keeps the platform's own checked state, focus ring and keyboard behaviour. */
  input[type=checkbox], input[type=radio] {
    width: 26px !important; height: 26px; margin: 9px 6px 9px 0;
    accent-color: var(--accent);
  }
  /* The label is the target too, so the whole row of text is tappable rather than
     just the box. */
  label.row { min-height: 44px; align-items: center; }
  button, .button, select { min-height: 44px; }
}

/* ---------------------------------------------------------------------------
   The label preview holds still. Stepping through a batch changes the artwork but
   must not change the layout: a panel that resizes with its contents shoves
   everything below it around, which reads as the page jumping on every press.
   --------------------------------------------------------------------------- */
.labelstage {
  height: 190px;                 /* fixed, so a 2x1 and a 4x6 occupy the same space */
  display: flex; align-items: center; justify-content: center;
  padding: .3rem 0 .9rem;
}
/* The whole panel holds a constant height too, not just the stage. The verdict block
   grows when a barcode fails - an extra red line - and without this the card resized
   on the one press where you most wanted to compare it with the last one. */
.labelcard { min-height: 430px; }

/* The preview STAYS PUT while the setup panel scrolls under it.
   Every control below this card changes what the card shows, and the panel is taller
   than a screen - so without this, opening the designer scrolls the label off the top
   and you are editing a thing you cannot see. That is the whole job of a preview.
   Sticky rather than a second copy inside the panel: two previews would drift, and the
   one nobody is looking at would be the one that goes wrong. */
@media (min-width: 901px) {
  .labelcard {
    position: sticky;
    /* Clears the masthead, which is itself sticky. */
    top: 4.25rem;
    z-index: 2;
  }
}
/* On one column the preview sits above the setup, so the same trick works - but a
   190px card pinned to a phone screen eats a third of it. Only where there is height
   to spare. */
@media (max-width: 900px) and (min-height: 760px) {
  .labelcard { position: sticky; top: 3.5rem; z-index: 2; }
}
.labelframe {
  border: 1px solid var(--rule); border-radius: 4px; overflow: hidden;
  box-shadow: var(--shadow); background: #fff; line-height: 0;
  max-width: 100%; max-height: 100%;
}
.labelframe svg { max-width: 100%; max-height: 170px; height: auto; width: auto; display: block; }

/* On a wide screen the preview follows you down the list instead of scrolling away. */
@media (min-width: 901px) {
  main > .stack:last-child { position: sticky; top: 1rem; }
}

.chip {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-size: .7rem; font-weight: 650; font-variant-numeric: tabular-nums;
}

/* State reads as shape as well as colour, so it survives a glance and a colourblind
   reader. */
.pill {
  display: inline-flex; align-items: center; gap: .35rem; padding: .12rem .5rem;
  border-radius: 999px; font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  border: 1px solid currentColor;
}
.pill.good { color: var(--good); }
.pill.warn { color: var(--warn); }
.pill.bad  { color: var(--bad); }
/* A "will scan" pill filled with the brand's pastel green - the semantic colour still
   carries the meaning, the brand colour carries the identity. */
.pill.good { background: color-mix(in srgb, var(--green) 30%, transparent); }
.pill.bad  { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); }

/* The whole kit, reachable by name. Kept out of the greys on purpose: these are trim,
   and trim that can restyle body text is how a brand file breaks a page. */
.brand-pink { color: var(--pink); }
.brand-blue { color: var(--blue); }
.brand-lightblue { color: var(--light-blue); }
.brand-gold { color: var(--gold); }
.brand-green { color: var(--green); }

/* Collapsible setup. The summary has to be useful shut, or it is just a thing to open. */
details > summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline;
  gap: .7rem; flex-wrap: wrap; padding: .1rem 0;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "\25B8"; color: var(--ink-3); font-size: .8rem;
  transition: transform .12s ease; display: inline-block;
}
details[open] > summary::before { transform: rotate(90deg); }
.sumtitle {
  font-size: .7rem; font-weight: 650; letter-spacing: .11em;
  text-transform: uppercase; color: var(--ink-3);
}
.summary-line { font-size: .76rem; color: var(--ink-3); }
details[open] .summary-line { opacity: .55; }
details > summary:hover .sumtitle, details > summary:hover .summary-line { color: var(--ink); }

/* Sections inside a panel, so related controls read as a group rather than a wall.
   A hairline and a small grey heading was not enough: with eight groups of number
   boxes stacked up you could not tell which heading owned which row, so "what am I
   editing" had to be answered by guessing. Each section now has a visible band with
   its name in it, and the controls sit indented under that band. */
.section {
  margin-top: 1.1rem;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  padding: 0 .8rem .85rem;
  background: color-mix(in srgb, var(--accent) 2%, transparent);
}
.section > h3 {
  margin: 0 -.8rem .75rem;
  padding: .42rem .8rem;
  font-size: .7rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-2);
  background: var(--rule-2);
  border-radius: 9px 9px 0 0;
  display: flex; align-items: center; gap: .5rem;
}
/* A short accent stub on the heading, so the eye finds the start of a group before
   it reads the word. */
.section > h3::before {
  content: ''; flex: 0 0 auto;
  width: .22rem; height: .8em; border-radius: 2px;
  background: var(--accent);
}
/* The section holding the element you are editing right now. Same purple as the
   dashed guide box on the label, so the two read as one thing. */
.section.editing {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.section.editing > h3 {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--ink);
}

/* ---------------------------------------------------------------------------
   Phone layout. The top nav becomes a bottom tab bar, because the top of a phone
   held one-handed is the one place a thumb cannot reach. Cards go edge to edge and
   lose their outer corners, which is how a native grouped list looks.
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  header { padding: .7rem .9rem; }
  header nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--rule);
    padding: .3rem .5rem calc(.3rem + env(safe-area-inset-bottom));
    gap: 0; justify-content: space-around;
  }
  header nav a {
    flex: 1; text-align: center; border-radius: 10px; padding: .55rem .3rem;
    font-size: .78rem; min-height: 44px; display: flex; align-items: center;
    justify-content: center;
  }
  header nav a[aria-current] { background: transparent; color: var(--accent); }
  header .rule, .tally { display: none; }
  main { padding: .9rem .75rem 4.5rem; gap: .9rem; }
  .card { border-radius: 14px; padding: .9rem 1rem; }
  .wordmark .shop { display: none; }

  /* A 7-column table cannot fit 375px. The extra columns fold into a subtitle under
     the name, which is how every native list on the platform does it. */
  .col-var, .col-code, .col-price, .col-stock { display: none; }
  .sub { display: block; }
  thead { display: none; }
  tbody td { padding: .55rem .5rem; }
  .scroll { max-height: none !important; overflow-y: visible !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
