/* ============================================================
   LABEL MAKER FOR SCHOOLS — styles
   (Screen UI. The print + sheet geometry below is kept exact.)
   ============================================================ */

:root {
  --primary: #1d4ed8;      /* runtime-overridden from config.js */
  --primary-dark: #1e40af; /* runtime-overridden from config.js */
  --navy: #102a56;
  --blue: #1464e8;
  --blue-soft: #f4f8fd;
  --ink: #16345f;
  --body: #3f5170;
  --muted: #6b7f9d;
  --bg: #eef2f8;
  --panel: #ffffff;
  --border: #dbe6f2;
  --pale: #eef4ff;
  --ok: #10a875;
  --radius: 11px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--body);
  line-height: 1.45;
}

[hidden] { display: none !important; }

.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;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(100deg, #102a56 0%, #0b1b3a 100%);
  color: #fff;
}
.header-inner {
  max-width: 1540px; margin: 0 auto; padding: 13px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-logo {
  display: none; width: auto; height: 46px; max-width: 180px;
  object-fit: contain; border-radius: 8px;
}
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary); color: #fff; font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center; letter-spacing: 1px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}
.brand-title { margin: 0; font-size: 19px; letter-spacing: .2px; font-weight: 800; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: #b9c9e2; }
.header-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.header-link {
  color: #fff; text-decoration: none; font-size: 12.5px; font-weight: 600;
  border: 1px solid rgba(255,255,255,.28); border-radius: 8px; padding: 7px 12px;
  transition: background .12s;
}
.header-link:hover { background: rgba(255,255,255,.1); }
.gdpr-badge {
  display: flex; gap: 9px; align-items: center;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  padding: 7px 13px; border-radius: 10px;
}
.gdpr-dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); flex: none; }
.gdpr-badge strong { font-size: 12px; display: block; line-height: 1.2; }
.gdpr-badge small { font-size: 10.5px; color: #b9c9e2; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1540px; margin: 24px auto; padding: 0 24px;
  display: grid; grid-template-columns: minmax(500px, .98fr) minmax(560px, 1.02fr);
  gap: 24px; align-items: start;
}
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
}
@media (max-width: 560px) {
  .layout { margin: 16px auto; padding: 0 14px; }
}

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
}
.controls-panel { border-top: 3px solid var(--primary); }
.card-title { margin: 0; font-size: 18px; color: var(--ink); font-weight: 800; }
.card-sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.panel-title { margin: 0; font-size: 15px; color: var(--ink); font-weight: 800; }
.preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.preview-meta { font-size: 12px; color: var(--muted); }
.preview-panel { position: sticky; top: 18px; }

/* ---------- Numbered steps ---------- */
.step { margin-top: 26px; }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.step-title { margin: 0; font-size: 15px; font-weight: 800; color: var(--ink); }

/* ---------- Upload ---------- */
.upload-area {
  border: 2px dashed #c3d4ec; border-radius: var(--radius);
  padding: 30px 16px; text-align: center; cursor: pointer;
  background: #fbfdff; transition: border-color .15s, background .15s;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--primary); background: #f4f8fd; }
.upload-icon {
  width: 46px; height: 46px; margin: 0 auto; border-radius: 50%;
  background: var(--blue-soft); border: 1px solid #d6e4f5;
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.upload-main { margin: 10px 0 5px; font-size: 14.5px; color: var(--body); }
.upload-hint { margin: 0; font-size: 11.5px; color: var(--muted); }
.upload-error { color: #b91c1c; font-size: 12px; margin: 10px 0 0; }
.linklike { color: var(--primary); text-decoration: underline; cursor: pointer; }

.file-status {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 12px; padding: 9px 12px; border-radius: 9px;
  background: #e9faf2; border: 1px solid #b9e6cf; font-size: 13px; color: #14653e;
}

/* ---------- Buttons ---------- */
.btn-primary {
  width: 100%; padding: 15px 18px; margin-top: 18px;
  background: var(--primary); color: #fff; border: 0; border-radius: var(--radius);
  font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 10px rgba(29,78,216,.28);
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--primary-dark);
  border-radius: 9px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.btn-ghost:hover { background: #f4f8fd; }
.btn-sm { margin-top: 0; }

.btn-soft {
  background: var(--blue-soft); border: 1px solid #d2e0f2; color: var(--blue);
  border-radius: 9px; padding: 7px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.btn-soft:hover { background: #eaf2fc; }
.sample-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.sample-row .btn-soft { display: inline-flex; align-items: center; justify-content: center; }
a.btn-soft { text-decoration: none; text-align: center; }
.download-link { margin-top: 0; }

/* ---------- Field mapping ---------- */
.field-map { margin-top: 12px; }

.sort-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.sort-row label { font-size: 13px; color: var(--body); font-weight: 600; }
.sort-row select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--body); cursor: pointer;
}
.sort-row select:focus { outline: 2px solid rgba(29,78,216,.25); outline-offset: 1px; }
.field-map > .field-map { margin-top: 0; }
.field-map > .field-map > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field-map select, .field-map .fixed-input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 9px; background: #fff; font-size: 13.5px; color: var(--ink);
  font-family: inherit;
}
.field-map select:focus, .field-map .fixed-input:focus { outline: 2px solid rgba(29,78,216,.25); outline-offset: 1px; }
.hint-text { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

/* ---------- Advanced details / checklist ---------- */
.adv-details {
  margin-top: 14px; border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px;
  background: #fbfdff;
}
.adv-details summary { cursor: pointer; font-size: 13px; color: var(--primary-dark); font-weight: 700; }
.adv-details summary:hover { color: var(--blue); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 9px 0; cursor: pointer; color: var(--body); }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.colour-row { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; }
.colour-row label { font-size: 13px; color: var(--body); }
.colour-row input[type="color"] { width: 42px; height: 30px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
.colour-row select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--body); cursor: pointer;
}
.colour-row select:focus { outline: 2px solid rgba(29,78,216,.25); outline-offset: 1px; }
.colour-row select:disabled { opacity: .55; cursor: not-allowed; }
.hint-inline { font-size: 12px; color: var(--muted); }

/* ---------- Template cards ---------- */
.template-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.template-card {
  position: relative;
  border: 1.5px solid var(--border); border-radius: 11px; padding: 11px 42px 11px 40px;
  cursor: pointer; background: #fff; text-align: left; font-family: inherit;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.template-card::before {
  content: ""; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid #b9c9e2; background: #fff;
}
.template-card::after {
  content: ""; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 26px; border-radius: 3px;
  border: 1.5px solid #c9d8ee; background: #fff;
  background-image:
    repeating-linear-gradient(to bottom, #e2ebf6 0 1px, transparent 1px 4px),
    repeating-linear-gradient(to right,  #e2ebf6 0 1px, transparent 1px 6px);
}
.template-card:hover { border-color: #9db8dd; }
.template-card.selected { border-color: var(--primary); background: #f4f8fd; box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.template-card.selected::before {
  border-color: var(--primary);
  background: radial-gradient(circle, var(--primary) 0 4.5px, #fff 5.5px);
}
.template-card.selected::after { border-color: var(--primary); opacity: .9; }
.template-card .t-code { display: block; font-weight: 800; font-size: 14px; color: var(--ink); letter-spacing: .02em; }
.template-card .t-size { display: block; font-size: 12px; color: var(--body); margin-top: 1px; }
.template-card .t-note { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- Label style cards ---------- */
.layout-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.layout-card {
  position: relative; display: flex; flex-direction: column; gap: 7px;
  border: 1.5px solid var(--border); border-radius: 11px; padding: 10px 10px 12px;
  cursor: pointer; background: #fff; text-align: left; font-family: inherit;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.layout-card:hover { border-color: #9db8dd; background: #fbfdff; }
.layout-card.selected { border-color: var(--primary); background: var(--pale); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.layout-card.selected::after {
  content: "✓"; position: absolute; top: -9px; right: -9px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--primary); color: #fff; font-size: 13px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(20,80,180,.35); line-height: 1;
}
.layout-name { font-size: 13px; font-weight: 700; color: var(--ink); }
.layout-desc { font-size: 11px; color: var(--muted); line-height: 1.35; }

/* ---------- Mini label previews (decorative, screen only) ---------- */
.l-prev {
  display: flex; flex-direction: column; gap: 4px; height: 82px;
  padding: 9px 8px; border: 1px solid #e3ecf8; border-radius: 8px; background: #fff; overflow: hidden;
}
.l-prev .p-name { font-size: 11px; font-weight: 800; color: #16345f; text-align: center; line-height: 1.1; }
.l-prev .p-subj {
  font-size: 8px; font-weight: 700; color: var(--primary); text-align: center;
  background: rgba(29,78,216,.1); border-radius: 999px; padding: 2px 5px; align-self: center;
}
.l-prev-classic .p-bar {
  background: var(--primary); color: #fff; font-size: 6px; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase; text-align: center;
  padding: 2px 0; border-radius: 2px;
}
.l-prev-classic .p-name { margin-top: auto; }
.l-prev-classic .p-meta { font-size: 7px; color: var(--muted); text-align: center; }
.l-prev-badge { align-items: center; }
.l-prev-badge .p-badge {
  width: 24px; height: 24px; border-radius: 50%; margin-top: auto;
  background: var(--primary); color: #fff; font-size: 8px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.l-prev-badge .p-subj { background: rgba(29,78,216,.14); color: #1d3fa0; }
.l-prev-minimal { justify-content: center; gap: 6px; }
.l-prev-minimal .p-subj { font-size: 9px; padding: 3px 8px; }

/* ---------- Print-offset calibration (Printing options) ---------- */
.cal-box { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }
.cal-title { font-size: 13px; font-weight: 700; color: var(--ink); margin: 0 0 4px; }
.cal-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; }
.cal-row label { font-size: 12px; color: var(--muted); width: 70px; flex: 0 0 auto; }
.cal-row label span { font-weight: 700; color: var(--primary-dark); }
.cal-row input {
  width: 90px; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit;
}
.cal-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.cal-btns .btn-ghost { margin-top: 0; }
.cal-status {
  margin: 8px 0 0; font-size: 12px; color: var(--primary-dark);
  transition: opacity .4s; opacity: 0; line-height: 1.45;
}

/* ---------- How it works ---------- */
.about-block {
  margin-top: 18px; padding: 13px 15px; background: #f7f9fc;
  border: 1px solid var(--border); border-radius: 11px; font-size: 12.5px;
}
.about-block h3 { margin: 0 0 6px; font-size: 13px; color: var(--ink); }
.about-block ul { margin: 0; padding-left: 16px; }
.about-block li { margin: 3px 0; }
.how-list { margin: 0; padding-left: 16px; }
.how-list li { margin: 4px 0; }
.print-note { font-size: 12px; color: var(--muted); text-align: center; margin: 10px 0 0; }

/* ---------- Privacy strip ---------- */
.privacy-strip {
  margin-top: 14px; padding: 10px 13px; border-radius: 10px;
  background: #ecf9f3; border: 1px solid #c2ecdb;
  font-size: 12px; color: #14653e;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.privacy-strip a { color: #0c7a4e; font-weight: 600; margin-left: auto; }

/* Calibration test sheet — mm ruler down the left edge & along the top */
.cal-tick { position: absolute; left: 0; width: 6mm; background: rgba(17,17,17,.55); }
.cal-num { position: absolute; left: 7mm; font-size: 7px; line-height: 5mm; color: #666; }
.cal-hick { position: absolute; top: 0; background: rgba(17,17,17,.7); width: 0.4mm; height: 4mm; }
.cal-hick.big { height: 5.5mm; }
.cal-head {
  position: absolute; top: 8mm; left: 30mm; z-index: 0;
  font-size: 10px; color: #888;
}

/* ---------- Preview scroll area (screen only) ---------- */
.sheet-scroll {
  overflow-x: auto; max-height: calc(100vh - 250px); overflow-y: auto;
  background: radial-gradient(circle, #cfddf0 1.15px, transparent 1.45px);
  background-size: 18px 18px;
  border: 1px solid var(--border); border-radius: 12px; padding: 18px;
  scrollbar-width: thin;
}
.preview-stage { position: relative; }
.a4-badge {
  position: absolute; top: 22px; right: 28px; z-index: 2; pointer-events: none;
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  padding: 4px 10px; box-shadow: 0 2px 8px rgba(20,60,120,.14);
}
@media (max-width: 560px) {
  .template-list, .layout-cards { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------
   ON-SCREEN A4 SHEET (live preview)
   ------------------------------------------------------------ */
.sheet {
  width: 210mm; height: 297mm;
  background: #fff; margin: 0 auto 22px; position: relative;
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
  page-break-after: always;
}
.sheet-pad { position: absolute; inset: 0; }

/* Label cells positioned in millimetres (driven by JS inline styles) */
.label-cell {
  position: absolute; overflow: hidden;
}

/* Guide outlines (dashed) — hidden when toggled off / when printing clean */
.label-cell.guides::after {
  content: ""; position: absolute; inset: 0;
  border: 0.35mm dashed #d3382c; border-radius: var(--r, 1.6mm); pointer-events: none;
}
.sheet.no-guides .label-cell.guides::after { display: none; }

/* Label interior */
.label-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--r, 1.6mm);
}
/* colour = single accent band = true, else text-only */
.label-inner.color {
  background: var(--label-bg, #ffffff);
}

.label-school {
  flex: none; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  text-align: center; white-space: nowrap; overflow: hidden;
  font-size: var(--school-fs, 3mm); padding: 4% 6% 0;
}
.label-school.bar {
  color: var(--bar-text, #fff); background: var(--bar-bg, transparent);
  font-size: var(--school-fs, 3mm); padding: 2.5% 6%;
  display: flex; align-items: center; justify-content: center; gap: 3%;
}
.lbl-logo { height: calc(var(--school-fs, 3mm) * 1.5); width: auto; max-width: 22%; object-fit: contain; }
.lbl-school-text { overflow: hidden; text-overflow: ellipsis; }
.label-name {
  flex: 1 1 auto; font-weight: 800; line-height: 1.15;
  font-size: var(--name-fs, 5mm);
  display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden;
  padding: 0 6%;
}
.label-subject {
  flex: none; text-align: center; font-weight: 600; padding: 0 10% 4%;
  font-size: var(--subj-fs, 3mm);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.label-meta {
  flex: none; display: flex; justify-content: center; gap: 6%; padding: 0 8% 3%;
  font-size: var(--meta-fs, 2.5mm); text-align: center;
}
.label-meta span { font-weight: 600; white-space: nowrap; overflow: hidden; }

/* Different arrangement modes */
.label-inner.badge .label-name { align-items: center; padding-bottom: 2%; }
.label-inner.badge .label-subject {
  background: var(--accent-soft, #e2e8f0); border-radius: 99px; margin: 0 8% 4%;
  padding: 1.5% 4%;
}
/* Badge layout: put the logo above the school name, centred on the strip */
.label-inner.badge .label-school {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; white-space: normal;
}
.label-inner.badge .label-school.bar { padding: 3.5% 6%; }
.label-inner.badge .lbl-school-text { max-width: 100%; }
.label-inner.minimal .label-school { display: none; }
.label-inner.minimal .label-meta { display: none; }
.app-footer {
  background: #0b1b3a; color: #b9c9e2; width: 100%;
  padding: 15px 24px 18px; font-size: 12px;
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center;
}
.footer-sep { color: rgba(255,255,255,.25); }
.footer-link { color: #fff; text-decoration: none; font-weight: 600; }
.footer-link:hover { text-decoration: underline; }

/* ============================================================
   PRINT — exact A4 at 100%. Hide the whole UI.
   ============================================================ */
@page {
  size: A4 portrait;
  margin: 0;
}

@media screen {
  #printRoot { display: none; }
}

@media print {
  body { background: #fff; }
  .app-header, .layout .controls-panel, .preview-panel, .app-footer,
  .sheet-scroll { display: none !important; }

  /* Hide every body child except #printRoot — prevents Chrome/Edge adding
     a blank trailing page (the in-flow siblings create a pagination break). */
  body > :not(#printRoot) { display: none !important; }

  #printRoot { display: block; }

  .sheet.print-sheet {
    width: 210mm; height: 296.8mm; margin: 0; box-shadow: none;
    page-break-after: always; break-after: page; position: relative;
  }
  .sheet.print-sheet:last-child { page-break-after: auto; break-after: auto; }

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