:root {
  --bg: #f3f5f7;
  --ink: #101820;
  --muted: #667085;
  --line: #d7dde3;
  --brand: #0d7c66;
  --brand-strong: #075a4a;
  --accent: #f2c94c;
  --panel: #ffffff;
  --danger: #a44343;
  --label-w: 50mm;
  --label-h: 30mm;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Tahoma, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workbench {
  max-width: 1180px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 42px);
}

.status-pill {
  min-width: 150px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.status-pill.connected {
  color: var(--brand-strong);
  border-color: #91cdbf;
  background: #e8f6f2;
}

.status-pill.warning {
  color: #8a5a00;
  border-color: #e3c36e;
  background: #fff7df;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 430px) 1fr;
  gap: 18px;
  align-items: start;
}

.panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.controls-panel {
  padding: 16px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.tab,
.secondary,
.queue-head button,
.queue-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.tab {
  padding: 9px 8px;
}

.tab.active {
  border-color: var(--brand);
  background: #e8f6f2;
  color: var(--brand-strong);
  font-weight: 700;
}

.form-grid,
.settings-box,
.api-box {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(13, 124, 102, .15);
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hidden {
  display: none;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.primary,
.secondary {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.primary {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.primary:disabled,
.secondary:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.ble-notice {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid #e3c36e;
  border-radius: 8px;
  background: #fff7df;
  color: #5f4200;
  font-size: 13px;
  line-height: 1.7;
}

.queue {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.queue-head h2 {
  margin: 0;
  font-size: 18px;
}

.queue-head button {
  padding: 7px 10px;
}

.queue-list {
  display: grid;
  gap: 8px;
  max-height: 210px;
  overflow: auto;
}

.queue-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  text-align: start;
}

.queue-item.active {
  border-color: var(--brand);
  background: #f0faf7;
}

.preview-panel {
  min-height: 620px;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.label-stage {
  display: grid;
  place-items: center;
  min-height: 560px;
  padding: 30px;
  background:
    linear-gradient(90deg, rgba(16, 24, 32, .045) 1px, transparent 1px),
    linear-gradient(rgba(16, 24, 32, .045) 1px, transparent 1px);
  background-size: 18px 18px;
}

.card-label {
  width: var(--label-w);
  height: var(--label-h);
  display: grid;
  grid-template-rows: 4.2mm 4mm 4mm 3mm 9mm 2.2mm;
  gap: .55mm;
  padding: 1.3mm;
  border: 1px dashed #8c99a5;
  background: #fff;
  color: #000;
  direction: rtl;
  overflow: hidden;
  box-shadow: 0 20px 45px rgba(16, 24, 32, .16);
}

.label-brand,
.credential-row,
.meta-grid,
.code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5mm;
}

.label-brand strong {
  font-size: 10pt;
  line-height: 1;
}

.label-brand span {
  padding: 1mm 1.5mm;
  border-radius: 3px;
  background: var(--accent);
  font-weight: 700;
  font-size: 6.2pt;
  white-space: nowrap;
}

.credential-row {
  border: 1px solid #000;
  padding: .35mm .8mm;
}

.credential-row span {
  color: #333;
  font-size: 5.3pt;
}

.credential-row strong {
  font-size: 8.2pt;
  letter-spacing: 0;
}

.meta-grid {
  font-size: 5.5pt;
}

.code-row {
  align-items: end;
}

#qrCode,
#qrCode canvas,
#qrCode img {
  width: 9mm;
  height: 9mm;
  image-rendering: pixelated;
}

#barcodeSvg {
  width: 28mm;
  height: 8.5mm;
}

.card-label p {
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 5pt;
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .layout {
    display: grid;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .actions,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .preview-panel {
    min-height: auto;
  }

  .label-stage {
    min-height: 340px;
    padding: 18px;
  }
}

@media print {
  @page {
    size: 50mm 30mm;
    margin: 0;
  }

  html,
  body {
    width: var(--label-w);
    height: var(--label-h);
    margin: 0;
    background: #fff;
    overflow: hidden;
  }

  .topbar,
  .controls-panel,
  .preview-toolbar {
    display: none;
  }

  .app-shell,
  .workbench,
  .layout,
  .preview-panel,
  .label-stage {
    display: block;
    width: var(--label-w);
    min-height: 0;
    height: var(--label-h);
    margin: 0;
    padding: 0;
    border: 0;
    background: #fff;
    overflow: hidden;
  }

  #printArea,
  #printArea * {
    visibility: visible;
  }

  #printArea {
    position: static;
    width: var(--label-w);
    height: var(--label-h);
    border: 0;
    box-shadow: none;
  }
}
