:root {
  --ink: #10192b;
  --ink-2: #27344d;
  --muted: #69758c;
  --line: #d8deea;
  --line-strong: #b8c2d3;
  --paper: #ffffff;
  --canvas: #edf1f7;
  --accent: #f25c3d;
  --accent-dark: #d9482c;
  --accent-soft: #fff0ec;
  --blue: #2f61d5;
  --shadow: 0 16px 38px rgba(22, 34, 56, .12);
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    linear-gradient(rgba(16,25,43,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16,25,43,.028) 1px, transparent 1px),
    var(--canvas);
  background-size: 24px 24px;
  font-size: 16px;
}

button, input, select { font: inherit; }
button, label.drop-zone { -webkit-tap-highlight-color: transparent; }

button:focus-visible, input:focus-visible, select:focus-visible, label.drop-zone:focus-within {
  outline: 3px solid rgba(47, 97, 213, .28);
  outline-offset: 2px;
}

.topbar {
  min-height: 78px;
  padding: 14px 22px;
  background: var(--ink);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: 0 8px 24px rgba(10, 17, 31, .18);
  position: relative;
  z-index: 10;
}

.brand, .top-actions { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.02em; }
.brand p { margin: 3px 0 0; color: #aeb8cb; font-size: .82rem; }

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--accent);
}
.brand-mark i { display: block; background: white; }

.privacy-note {
  font-size: .78rem;
  color: #bec7d7;
  padding-left: 20px;
  position: relative;
}
.privacy-note::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 9px;
  height: 9px;
  border: 2px solid #7ed7af;
  border-radius: 50%;
  transform: translateY(-50%);
}

.button {
  appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: white;
  color: var(--ink);
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); border-color: #8996ab; }
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button.secondary { background: var(--ink); border-color: var(--ink); color: white; }
.button.ghost { background: transparent; color: white; border-color: #4a5670; }
.button.small { font-size: .86rem; padding: 8px 11px; }

.workspace {
  height: calc(100vh - 78px);
  display: grid;
  grid-template-columns: 280px minmax(440px, 1fr) minmax(430px, 1fr);
  gap: 1px;
  background: var(--line);
  overflow: hidden;
}

.panel {
  background: #f9fbfe;
  min-width: 0;
  overflow-y: auto;
}
.panel-heading {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.panel-heading h2 { margin: 2px 0 0; font-size: 1.08rem; letter-spacing: -.01em; }
.eyebrow { text-transform: uppercase; letter-spacing: .11em; font-size: .67rem; font-weight: 800; color: var(--accent-dark); }
.split-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.step-block { padding: 19px 18px; border-bottom: 1px solid var(--line); }
.step-label { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; font-size: .9rem; }
.step-label span {
  width: 23px; height: 23px; border-radius: 7px; display: grid; place-items: center;
  background: var(--ink); color: white; font-size: .72rem; font-weight: 800;
}
.upload-check { margin-left: auto; width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: #e6f5ec; color: #137a43; border: 1px solid #b8e2c7; font-size: .88rem; font-style: normal; font-weight: 900; }
.upload-check[hidden] { display: none; }

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 16px;
  border: 1.5px dashed #aeb9ca;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  text-align: center;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--blue); background: #f3f7ff; }
.drop-zone.compact { min-height: 102px; }
.drop-zone strong { font-size: .9rem; }
.drop-zone small { margin-top: 4px; color: var(--muted); font-size: .72rem; }
.upload-icon { font-size: 1.25rem; line-height: 1; margin-bottom: 8px; color: var(--blue); font-weight: 800; }
.upload-icon.image { transform: rotate(90deg); }
.file-status { min-height: 20px; margin-top: 8px; padding: 6px 8px; border-radius: 7px; color: var(--muted); background: #f4f6fa; font-size: .72rem; overflow-wrap: anywhere; }
.file-status.ready { color: #17663f; background: #edf8f1; border: 1px solid #d1ead9; font-weight: 700; }

.text-button {
  appearance: none;
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--blue);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.text-button:hover { text-decoration: underline; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; }

.control-label { display: block; color: var(--muted); font-size: .74rem; font-weight: 700; margin-bottom: 6px; }
.page-control-spaced { margin-top: 12px; }
.help-note { display: block; margin-top: 5px; color: var(--muted); font-size: .72rem; line-height: 1.4; }
select, input[type="number"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 9px;
  background: white;
  color: var(--ink);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--ink-2); font-size: .82rem; cursor: pointer; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--accent); }

.editor-panel { display: flex; flex-direction: column; }
.editor-note { padding: 11px 20px; color: var(--muted); font-size: .78rem; background: #f4f7fb; border-bottom: 1px solid var(--line); }
.editor-stage {
  min-height: 0;
  flex: 0 0 auto;
  padding: 28px;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  transition: height .18s ease;
  background:
    linear-gradient(45deg, #e4e9f1 25%, transparent 25%),
    linear-gradient(-45deg, #e4e9f1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4e9f1 75%),
    linear-gradient(-45deg, transparent 75%, #e4e9f1 75%), #f0f3f8;
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  border-bottom: 1px solid var(--line);
}

.card-canvas {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 4.25 / 5.5;
  background-color: white;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.card-canvas.landscape { aspect-ratio: 5.5 / 4.25; }

.field-node {
  position: absolute;
  cursor: grab;
  border: 1px dashed transparent;
  padding: 2px 3px;
  min-height: 20px;
  line-height: 1.06;
  overflow: visible;
  overflow-wrap: break-word;
  transform-origin: center center;
  white-space: pre-line;
  overflow-wrap: normal;
  word-break: normal;
}
.field-node:hover { border-color: rgba(47,97,213,.55); }
.field-node.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47,97,213,.16); background: rgba(255,255,255,.28); }
.field-node:active { cursor: grabbing; }
.barcode-node {
  position: absolute;
  cursor: grab;
  border: 1px dashed transparent;
  padding: 2px;
  min-height: 24px;
  line-height: 1;
  color: #10192b;
  transform-origin: center center;
  overflow: visible;
}
.barcode-node svg { display: block; width: 100%; height: 100%; overflow: visible; }
.barcode-node:hover { border-color: rgba(47,97,213,.55); }
.barcode-node.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47,97,213,.16); background: rgba(255,255,255,.28); }
.barcode-node:active { cursor: grabbing; }

.field-list-header { padding: 15px 20px 8px; display: flex; justify-content: space-between; font-size: .8rem; }
.field-list-header span { color: var(--muted); }
.field-list { padding: 0 14px 10px; display: grid; gap: 6px; }
.field-item {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: white;
  color: var(--ink); display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; text-align: left;
}
.field-item:hover { border-color: #a7b2c4; }
.field-item.active { border-color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.field-item strong { display: block; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-item small { color: var(--muted); font-size: .68rem; }
.field-item span:first-child { min-width: 0; }
.field-chip { flex: 0 0 auto; border-radius: 6px; padding: 4px 6px; background: #eef2f8; color: var(--ink-2); font-size: .65rem; font-weight: 800; }

.format-panel { margin: 2px 14px 18px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.format-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.format-title strong { display: block; margin-top: 2px; font-size: .9rem; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.form-grid { display: grid; grid-template-columns: 1fr 100px; gap: 10px; }
.form-grid label { color: var(--muted); font-size: .68rem; font-weight: 700; }
.form-grid label > select, .form-grid label > input, .number-unit { margin-top: 5px; }
.form-grid .wide { grid-column: 1 / -1; }
.number-unit { display: flex; align-items: center; }
.number-unit input { border-radius: 8px 0 0 8px; }
.number-unit span { height: 38px; display: grid; place-items: center; padding: 0 8px; background: #eef2f7; border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 8px 8px 0; font-size: .7rem; }
input[type="color"] { width: 100%; height: 38px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 8px; background: white; }
.range-line { display: flex; align-items: center; gap: 10px; margin-top: 5px; }
.range-line input { flex: 1; accent-color: var(--accent); }
.range-line output { min-width: 34px; color: var(--ink); }
.button-row { display: flex; gap: 6px; margin-top: 12px; }
.editor-actions { display: flex; gap: 6px; }
.editor-actions .button { white-space: nowrap; }
.toggle-button, .icon-button {
  width: 38px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 8px;
  background: white; color: var(--ink); cursor: pointer;
}
.toggle-button:hover, .icon-button:hover { border-color: #8592a6; }
.toggle-button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: white; }
.toggle-button.align { font-size: 1.1rem; justify-content: start; padding: 0 7px; }
.toggle-button.center-icon { justify-content: center; }
.toggle-button.right-icon { justify-content: end; }
.icon-button { font-size: 1.35rem; }
.icon-button.danger { color: #b83728; border-color: #efc8c0; background: #fff7f5; }

.preview-panel { background: #eef2f7; }
.record-badge { border-radius: 999px; padding: 6px 9px; background: var(--accent-soft); color: var(--accent-dark); font-size: .72rem; font-weight: 800; }
.preview-toolbar { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px; }
.preview-toolbar .icon-button { width: 32px; height: 30px; background: white; }
.preview-toolbar span { min-width: 96px; text-align: center; font-size: .76rem; font-weight: 700; color: var(--ink-2); }
.sheet-wrap { padding: 0 24px 18px; display: grid; place-items: center; }
.sheet {
  width: min(100%, 480px);
  aspect-ratio: 8.5 / 11;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  background: white;
  box-shadow: 0 18px 45px rgba(18,30,52,.18);
  overflow: hidden;
}
.sheet.landscape { aspect-ratio: 11 / 8.5; }
.preview-card {
  position: relative;
  background-color: white;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
}
.sheet.cut-lines .preview-card { outline: 1px dashed rgba(16,25,43,.28); outline-offset: -1px; }
.preview-card.empty { background: repeating-linear-gradient(45deg,#fafbfc,#fafbfc 8px,#f5f7fa 8px,#f5f7fa 16px); }
.preview-card .field-node { cursor: default; border: 0; box-shadow: none; background: transparent; }
.preview-footer { padding: 0 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.preview-footer span { font-size: .74rem; color: var(--muted); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 340px;
  padding: 12px 15px;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  font-size: .82rem;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.print-root { display: none; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 250px minmax(400px, 1fr); overflow-y: auto; height: auto; min-height: calc(100vh - 78px); }
  .preview-panel { grid-column: 1 / -1; }
  .sheet-wrap { padding-inline: 12%; }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 13px 16px; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .privacy-note { flex: 1; }
  .workspace { display: block; }
  .panel { overflow: visible; }
  .panel-heading { position: static; }
  .setup-panel, .editor-panel, .preview-panel { border-bottom: 1px solid var(--line); }
  .editor-stage { min-height: 0; padding: 20px; }
  .sheet-wrap { padding-inline: 14px; }
  .privacy-note { font-size: .7rem; }
}

@page { size: letter portrait; margin: 0; }

@media print {
  html, body { background: white !important; margin: 0 !important; padding: 0 !important; }
  body > :not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-page {
    width: 8.5in;
    height: 11in;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    break-after: page;
    page-break-after: always;
    overflow: hidden;
  }
  .print-page.landscape { width: 11in; height: 8.5in; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page .preview-card { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .print-page.cut-lines .preview-card { outline: .5pt dashed rgba(16,25,43,.32); outline-offset: -1px; }
}
