:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --panel: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --accent: #2563eb;
  --border: #d4d4d8;
  --ok: #16a34a;
  --err: #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181b;
    --panel: #27272a;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --border: #3f3f46;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  padding: 24px;
}

h1 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

.app {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  gap: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.preview-wrap {
  display: flex;
  justify-content: center;
  padding: 24px;
}

/* --- Label (30mm x 50mm) --- */
.label {
  width: 50mm;
  height: 30mm;
  background: #ffffff;
  color: #000000;
  border: 1px solid #999;
  padding: 1.4mm 2mm;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
}

.label .line {
  font-size: 3mm;
  line-height: 3.6mm;
  white-space: nowrap;
}

.label .charge-line {
  display: flex;
  align-items: center;
  gap: 1.5mm;
}

.dc-symbol {
  width: 5mm;
  height: 2.6mm;
  color: #000;
  flex-shrink: 0;
}

#barcodeSvg {
  display: block;
  width: 46mm;
  height: 8.5mm;
  margin-top: 0.8mm;
}

.marks {
  position: absolute;
  right: 2mm;
  bottom: 1mm;
  display: flex;
  gap: 1.8mm;
  align-items: center;
  color: #000;
}

.marks svg {
  height: 3.4mm;
  width: auto;
  display: block;
}

.marks .weee-mark {
  height: 3.8mm;
}

/* --- Controls --- */
.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: -4px 0 12px;
  line-height: 1.4;
}

.hint code {
  background: var(--bg);
  border-radius: 4px;
  padding: 1px 4px;
}

.link-btn {
  display: inline;
  width: auto;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
  font-weight: 600;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-row {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.dot.ok {
  background: var(--ok);
}

.dot.err {
  background: var(--err);
}

#log {
  margin-top: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.78rem;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

details {
  margin-top: 12px;
}

details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

#zplPreview {
  width: 100%;
  margin-top: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  resize: vertical;
}

/* --- Print --- */
@media print {
  @page {
    size: 50mm 30mm;
    margin: 0;
  }
  body * {
    visibility: hidden;
  }
  #printArea,
  #printArea * {
    visibility: visible;
  }
  #printArea {
    position: absolute;
    top: 0;
    left: 0;
  }
  .label {
    border: none;
  }
}
