:root {
  --brand: #6d28d9;
  --brand-dark: #4c1d95;
  --brand-light: #ede9fe;
  --sidebar-w: 250px;
  --topbar-h: 56px;
}

body {
  background: #f4f5f9;
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}

.app-topbar {
  background: linear-gradient(90deg, var(--brand-dark), var(--brand));
  min-height: var(--topbar-h);
  flex-wrap: nowrap;
  position: sticky;
  top: 0;
  z-index: 1030;
}

.app-body {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

.app-sidebar {
  width: var(--sidebar-w);
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
}

@media (min-width: 992px) {
  .app-sidebar {
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
  }
}

.sidebar-inner {
  padding-top: .75rem;
}

.nav-section-title {
  text-transform: uppercase;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: #9ca3af;
  padding: .9rem 1rem .3rem;
}

.app-sidebar .nav-link {
  color: #374151;
  border-radius: .5rem;
  padding: .55rem .9rem;
  margin: .1rem .4rem;
  font-size: .93rem;
}

.app-sidebar .nav-link:hover {
  background: var(--brand-light);
  color: var(--brand-dark);
}

.app-sidebar .nav-link.active {
  background: var(--brand);
  color: #fff;
}

.app-sidebar .nav-link.disabled {
  color: #c7cbd3;
  cursor: default;
}

.app-content {
  flex: 1;
  padding: 1.25rem;
  min-width: 0;
}

.stat-card {
  border: none;
  border-radius: .9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: var(--brand-light);
  color: var(--brand);
}

.card {
  border: none;
  border-radius: .9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.table thead th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #6b7280;
  border-bottom-width: 1px;
}

.btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-brand:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
}

.login-card {
  width: 100%;
  max-width: 380px;
  border-radius: 1rem;
  border: none;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

/* Barcode label print styling */
@media print {
  body * { visibility: hidden; }
  .print-label, .print-label *,
  .print-batch, .print-batch * { visibility: visible; }
  .print-label {
    position: absolute;
    top: 0;
    left: 0;
  }
  /* Multiple labels (batch print): pin the whole group at the top-left,
     then let each label flow normally underneath, one per label pass. */
  .print-batch {
    position: absolute;
    top: 0;
    left: 0;
  }
  .print-batch .print-label {
    position: static;
    page-break-after: always;
  }
  .no-print { display: none !important; }
}

.print-label {
  width: 50mm;
  min-height: 30mm;
  border: 1px dashed #999;
  padding: 2mm 3mm;
  font-size: 9px;
  line-height: 1.25;
}
.print-label .lbl-code {
  font-weight: 700;
  font-size: 11px;
}
.print-label svg {
  width: 100%;
  height: auto;
}

/* Fabric roll sticker (article, code, shade, qty, description, barcode last).
   Size comes from Settings → Sticker size (default 60 x 35 mm label, 2 mm safe border => 56 x 31 mm sticker):
   --stk-w / --stk-h / --lbl-s are written into the page by fabric_label_style().
   Everything inside is laid out top-to-bottom and the barcode takes whatever height is left.
   Only plain mm / px here — NO vh / vw / min(): in some browsers' print preview those come out as 0 and the
   sticker then prints EMPTY. */
.fabric-label {
  --s: var(--lbl-s, 1);
  --u: calc(var(--s) * 1px);   /* "one design pixel" */
  width: var(--stk-w, var(--lbl-w, 60mm));
  height: var(--stk-h, var(--lbl-h, 35mm));
  min-height: 0;
  padding: calc(5.29 * var(--u)) calc(7.56 * var(--u));    /* 1.4mm / 2mm (kept small so the larger text still fits) */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  font-size: calc(10 * var(--u));
  /* Thermal printers print thin grey text faintly: pure black + bold, and everything centred */
  color: #000;
  font-weight: 600;
  text-align: center;
  justify-content: center;
}
.fabric-label > * { flex: 0 0 auto; }
.fabric-label { line-height: 1.15; }
/* Article / Code / Shade / Qty rows: small label word + bold value, one line each */
.fabric-label .lbl-row {
  font-size: calc(11 * var(--u) * var(--fit, 1));   /* --fit < 1 is set by the page script for long names */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fabric-label .lbl-article { font-size: calc(12.5 * var(--u) * var(--fit, 1)); }
.fabric-label .lbl-k { font-size: .88em; font-weight: 600; }
.fabric-label .lbl-v { font-weight: 700; }
.fabric-label .lbl-roll { font-size: .88em; font-weight: 600; }
.fabric-label .lbl-desc {
  font-size: calc(9.2 * var(--u));
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* The barcode comes last and takes whatever height is left, but never less than 8 mm so it scans well */
.fabric-label svg {
  flex: 1 1 0;
  height: 0;
  min-height: calc(30.24 * var(--u));   /* 8 mm */
  max-height: calc(52.91 * var(--u));   /* 14 mm */
  width: 100%;
  max-width: 100%;
  align-self: center;
  margin: calc(2.27 * var(--u)) 0;      /* 0.6 mm */
}
.fabric-label .lbl-bc { text-align: center; font-size: calc(10 * var(--u)); font-weight: 700; }

/* "Print as picture" mode (see fabric_label_picture_script in modules/fabric/_label.php): each sticker is swapped for
   a 203-dpi black & white picture of itself. On screen it gets a dashed outline like the normal sticker preview. */
.pic-img { display: block; border: 1px dashed #999; background: #fff; max-width: none; }

/* Version stamp shown above the stickers (never printed). If this text is missing on screen, the browser is still
   using an OLD cached copy of this stylesheet (the server lets browsers keep CSS for 7 days). */
.css-ver::after { content: "C-2026-10-30 (larger text)"; }
.css-ver-warn { display: none; }   /* an OLD cached stylesheet has no such rule, so the red warning shows by itself */

/* Test sticker (modules/fabric/test_label.php): solid frame = the whole label, dotted box = the fabric sticker
   (the label minus the safe border), ruler, a 50 mm bar. The thin dashed box at the page edge shows the page area
   the browser reports (it only appears if the browser supports vh/vw in print — that itself is a useful clue). */
.test-label {
  position: relative;
  width: calc(var(--lbl-w, 60mm) - 0.4mm);
  height: calc(var(--lbl-h, 35mm) - 0.6mm);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  color: #000;
  font-weight: 700;
  line-height: 1.1;
}
.test-label .tl-frame { position: absolute; left: 0; top: 0; width: calc(var(--lbl-w, 60mm) - 0.4mm); height: calc(var(--lbl-h, 35mm) - 0.6mm); border: 0.5mm solid #000; box-sizing: border-box; }
.test-label .tl-page { display: none; }
.test-label .tl-box { position: absolute; left: calc((var(--lbl-w, 60mm) - var(--stk-w, 56mm)) / 2); top: var(--lbl-b, 2mm);
  width: var(--stk-w, 56mm); height: var(--stk-h, 31mm); border: 0.3mm dotted #000; box-sizing: border-box; }
.test-label .tl-rule { position: absolute; left: 0; top: 0; }
.test-label .tl-rule-top  { width: var(--lbl-w, 60mm); height: 2mm;
  background: repeating-linear-gradient(to right, #000 0, #000 0.25mm, transparent 0.25mm, transparent 5mm); }
.test-label .tl-rule-top.tl-rule-long  { height: 3.4mm;
  background: repeating-linear-gradient(to right, #000 0, #000 0.3mm, transparent 0.3mm, transparent 10mm); }
.test-label .tl-rule-left { height: var(--lbl-h, 35mm); width: 2mm;
  background: repeating-linear-gradient(to bottom, #000 0, #000 0.25mm, transparent 0.25mm, transparent 5mm); }
.test-label .tl-rule-left.tl-rule-long { width: 3.4mm;
  background: repeating-linear-gradient(to bottom, #000 0, #000 0.3mm, transparent 0.3mm, transparent 10mm); }
.test-label .tl-num { position: absolute; font-size: 7px; line-height: 1; }
.test-label .tl-num-side { left: 3.6mm; top: 5mm; line-height: 10mm; }   /* line i is centred on the i-cm tick */
.test-label .tl-mid { position: absolute; left: calc(var(--lbl-w, 60mm) / 2); top: calc(var(--lbl-h, 35mm) / 2); transform: translate(-50%, -50%); text-align: center; white-space: nowrap; }
.test-label .tl-big { font-size: 11px; }
.test-label .tl-small { font-size: 7.5px; font-weight: 600; }
.test-label .tl-bar { width: 50mm; max-width: calc(var(--lbl-w, 60mm) - 6mm); height: 1.2mm; background: #000; margin: 1.6mm auto 0.6mm; }

/* Printing stickers (pages with <body class="labels-print">): hide the whole app screen so ONLY
   the stickers are on the paper. Each sticker is exactly one label (the @page size is set by
   fabric_label_style()), so a roll of labels feeds one sticker at a time with no blank labels. */
@media print {
  body.labels-print { background: #fff; }
  body.labels-print .app-topbar,
  body.labels-print .app-sidebar,
  body.labels-print .alert { display: none !important; }
  body.labels-print .app-body { display: block; min-height: 0; }
  body.labels-print .app-content { padding: 0; }
  body.labels-print * { visibility: visible; }
  body.labels-print .print-batch { position: static; display: block !important; }
  /* A label printer cannot print right up to the edge of the label. A sticker as big as the label then overflows
     onto a second page = a second label (barcode on one label, text on the next, blanks in between). So the fabric
     sticker is the label minus a "safe border" (Settings) and is moved down by that border, i.e. centred. */
  body.labels-print .print-label,
  body.labels-print .pic-img {
    position: relative;
    left: var(--lbl-dx, 0mm);                               /* fine-tune from Settings: right (+) / left (-) ... */
    top: calc(var(--lbl-dy, 0mm) + var(--lbl-b, 0mm));      /* ... down (+) / up (-); moves the print only, adds no pages */
    border: 0;
    margin: 0 auto;               /* if the paper is wider than the sticker, keep the sticker in the middle */
  }
  /* "Print as picture" mode: the picture is printed dot-for-dot (no smoothing) */
  body.labels-print .pic-img { image-rendering: pixelated; }
  /* test sticker: same size as the label, not moved down by the safe border */
  body.labels-print .test-label,
  body.labels-print .pic-test { top: var(--lbl-dy, 0mm); }
  body.labels-print .test-label .tl-page { display: block; position: fixed; left: 0; top: 0; width: 100vw; height: 100vh;
    border: 0.3mm dashed #000; box-sizing: border-box; }
  body.labels-print .print-batch .print-label,
  body.labels-print .print-batch .pic-img { break-after: page; page-break-after: always; }
  body.labels-print .print-batch .print-label:last-child,
  body.labels-print .print-batch .pic-img:last-child { break-after: auto; page-break-after: auto; }
}

/* A smaller variant for accessory stickers ("real small stickers") — same
   rules as .print-label above (it keeps that class too), just tighter. */
.print-label-sm {
  width: 30mm;
  min-height: 16mm;
  padding: 1.5mm 2mm;
  font-size: 7px;
}
.print-label-sm .lbl-code {
  font-size: 8px;
}
