/* EAN-tarrat. Tokens follow lasti's back office (apps/web/src/styles/main.css):
   warm paper, near-black ink, amber as the one action colour. */

:root {
  --paper: #faf8f5;
  --surface: #ffffff;
  --ink: #1d1b18;
  --ink-body: #3a3631;
  --ink-muted: #75695c;
  --line: rgba(0, 0, 0, 0.1);
  --line-strong: rgba(0, 0, 0, 0.2);
  --amber: #f5b335;
  --amber-ink: #1d1b18;
  --chosen: #fdf3dc;
  --danger: #a4372b;
  --radius: 6px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-body);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

h1,
h2 {
  color: var(--ink);
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 15px;
  font-weight: 700;
}

button,
input {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.top {
  margin-bottom: 16px;
}

.lede {
  margin: 4px 0 0;
  color: var(--ink-muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas:
    'products side'
    'preview preview';
  gap: 16px;
  align-items: start;
}

.products {
  grid-area: products;
}

.side {
  grid-area: side;
  display: grid;
  gap: 16px;
}

.preview {
  grid-area: preview;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'products' 'side' 'preview';
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.panel h2 {
  margin-bottom: 10px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-head h2 {
  margin: 0;
}

input[type='search'],
input[type='number'] {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 8px;
  min-height: 34px;
}

input[type='search'] {
  flex: 1 1 240px;
  max-width: 360px;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.table-wrap {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: var(--paper);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
  z-index: 1;
}

td.num,
th.num {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

td.ean {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th.pick,
td.pick {
  width: 36px;
  text-align: center;
}

tr.pickable {
  cursor: pointer;
}

tr.pickable:hover td {
  background: var(--paper);
}

tr.chosen td,
tr.chosen:hover td {
  background: var(--chosen);
}

tr.disabled td {
  color: var(--ink-muted);
}

.missing {
  font-size: 12px;
  color: var(--ink-muted);
}

.empty {
  color: var(--ink-muted);
  text-align: center;
  padding: 20px;
}

.chosen-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.chosen-card p {
  margin: 0;
}

.chosen-code {
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chosen-name {
  color: var(--ink);
  margin-top: 2px !important;
}

.field + .buttons {
  margin-top: 12px;
}

.summary {
  margin: 0 0 12px;
  font-weight: 600;
  color: var(--ink);
}

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

.buttons button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
}

.buttons button.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
  font-weight: 700;
}

.buttons button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint,
.muted {
  color: var(--ink-muted);
  font-size: 12.5px;
}

.hint {
  margin: 12px 0 0;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.field input {
  width: 100%;
}

.inline {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline input {
  width: 72px;
  flex: none;
}

details {
  margin-top: 14px;
}

summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0;
}

/* --- preview ------------------------------------------------------------- */

.preview-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.preview-wrap figure {
  margin: 0;
}

.preview-wrap figcaption {
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

/* A sheet is drawn at real size and scaled down, so the preview is the print. */
.scaler {
  --s: 0.5;
  width: calc(210mm * var(--s));
  height: calc(297mm * var(--s));
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  background: #fff;
}

.scaler .sheet {
  transform: scale(var(--s));
  transform-origin: 0 0;
}

@media (max-width: 520px) {
  .scaler {
    --s: 0.38;
  }
}

/* --- the sheet, shared by preview and print ---------------------------- */

.sheet {
  position: relative;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  background: #fff;
}

.sticker {
  position: absolute;
  overflow: hidden;
  color: #000;
}

.sticker.outline {
  outline: 0.2mm dashed rgba(0, 0, 0, 0.25);
  outline-offset: -0.1mm;
}

.sticker-in .bc svg {
  display: block;
}

.sticker-in .code,
.sticker-in .name {
  white-space: nowrap;
  line-height: 1.18;
  color: #000;
}

.sticker-in .code {
  font-weight: 700;
  margin-top: 0.6mm;
  font-variant-numeric: tabular-nums;
}

.sticker-in .name {
  font-weight: 500;
}

.slot-no {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 9pt;
  color: #555;
}

#print-root {
  display: none;
}

/* --- print --------------------------------------------------------------- */

@page {
  size: A4;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0;
    background: #fff;
  }

  .app {
    display: none;
  }

  #print-root {
    display: block;
  }

  #print-root .sheet {
    break-after: page;
    page-break-after: always;
  }

  #print-root .sheet:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  /* The test sheet's outlines must print solid, or a dashed line on a cheap
     laser vanishes and the calibration measures nothing. */
  #print-root .sticker.outline {
    outline: 0.2mm solid #000;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
