:root {
  --brand: #1e6b4a;
  --brand-dark: #145238;
  --brand-light: #e8f5ef;
  --accent: #2d5a87;
  --accent-light: #eef4fb;
  --bg: #f4f6f9;
  --surface: #fff;
  --text: #1a2332;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  padding-bottom: 4.5rem;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(30, 107, 74, 0.12), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(45, 90, 135, 0.08), transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

.login-brand {
  padding: 1.5rem 1.5rem 1rem;
  background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand) 100%);
  color: #fff;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.25rem;
}

.login-brand p {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  opacity: 0.9;
}

.login-form {
  padding: 1.25rem 1.5rem 0.5rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.875rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.login-remember {
  margin-bottom: 1rem;
}

.btn-login {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.9375rem;
}

.login-error {
  margin: 0.75rem 0 0;
  font-size: 0.8125rem;
  color: #dc2626;
  text-align: center;
}

.login-foot {
  margin: 0;
  padding: 0.75rem 1.5rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.header-auth {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.auth-user {
  font-size: 0.75rem;
  opacity: 0.9;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
}

@media (min-width: 768px) {
  body {
    padding-bottom: 0;
  }
}

body.mp-mode .back-home,
body.mp-mode .share-bar,
body.mp-mode #btnLogout,
body.mp-mode .mobile-bar {
  display: none !important;
}

body.mp-mode {
  padding-bottom: 0;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand) 45%, #2a8f62 100%);
  color: #fff;
  padding: 1.125rem 1rem 1.375rem;
  box-shadow: 0 2px 12px rgba(20, 82, 56, 0.25);
}

@media (min-width: 768px) {
  .header {
    padding: 1.375rem 2rem 1.5rem;
  }
}

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.625rem;
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: color 0.15s;
}

.back-home:hover {
  color: #fff;
}

.header h1 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0.35rem 0 0;
  opacity: 0.9;
  font-size: 0.8125rem;
  font-weight: 400;
}

.share-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
  padding: 0.625rem 0.75rem;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
}

.share-label {
  font-size: 0.8125rem;
  white-space: nowrap;
  opacity: 0.95;
}

.share-input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.75rem;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  color: #333;
  background: rgba(255, 255, 255, 0.95);
}

/* ── Layout ── */
.layout {
  max-width: 1140px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .layout {
    padding: 1.5rem;
    gap: 1.25rem;
  }
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }

  .preview-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .layout {
    display: flex;
    flex-direction: column;
  }

  .panel-print {
    order: -2;
  }

  .preview-panel {
    order: 0;
  }
}

/* ── Panels ── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.375rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: box-shadow 0.2s;
}

.panel:hover {
  box-shadow: var(--shadow-md);
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1.125rem;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}

.panel-highlight {
  border-color: #c8e6d4;
  background: linear-gradient(180deg, #fff 0%, #fafdfb 100%);
}

.panel-size {
  border-color: #dbeafe;
  background: linear-gradient(180deg, #fff 0%, #f8fbff 100%);
}

.panel-print {
  border-color: #b8d4c8;
  background: linear-gradient(180deg, #fff 0%, #f6fbf8 100%);
}

.preview-panel {
  border-color: var(--border);
}

/* ── Badges ── */
.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--brand-light);
  color: var(--brand-dark);
  vertical-align: middle;
}

.badge-muted {
  background: #f1f5f9;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Buttons ── */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.125rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:hover:not(:disabled) {
  background: #f8fafc;
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-needs-data {
  box-shadow: 0 2px 6px rgba(20, 82, 56, 0.18);
}

.btn-needs-data::after {
  content: '（需先添加标签）';
  font-size: 0.75rem;
  font-weight: 400;
  margin-left: 0.25rem;
  opacity: 0.85;
}

.btn.is-busy {
  opacity: 0.42;
  pointer-events: none;
}

.hint-warn {
  color: #b45309;
  font-weight: 500;
}

.system-print-block {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.intro-bluetooth {
  margin-top: 0;
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
  border-color: var(--brand-dark);
  color: #fff;
  box-shadow: 0 2px 6px rgba(20, 82, 56, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #22855a 0%, #0f4029 100%);
  border-color: #0f4029;
  color: #fff;
}

.btn-light {
  background: #fff;
  border-color: #fff;
  color: var(--brand-dark);
  font-weight: 600;
}

.btn-light:hover:not(:disabled) {
  background: #f0fdf4;
}

.btn-stop {
  background: #fff;
  border-color: #fca5a5;
  color: #dc2626;
  font-weight: 600;
}

.btn-stop:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.action-row .btn {
  flex: 1 1 auto;
  min-width: 120px;
}

.panel-print .btn-row {
  position: relative;
  z-index: 2;
}

/* ── Form controls ── */
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.875rem;
}

.field-row label {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 4.5rem;
}

.select,
.num-input,
.share-input {
  font-family: inherit;
}

.select {
  flex: 1;
  min-width: 160px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.select:focus,
.num-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30, 107, 74, 0.15);
}

.num-input {
  width: 4.75rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.text-input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30, 107, 74, 0.15);
}

.manual-panel {
  margin: 0.875rem 0 1rem;
  padding: 0.875rem;
  background: var(--brand-light);
  border: 1px solid rgba(30, 107, 74, 0.2);
  border-radius: var(--radius-sm);
}

.manual-title {
  margin: 0 0 0.625rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--brand-dark);
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

@media (min-width: 640px) {
  .manual-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.manual-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

.manual-field-wide {
  grid-column: 1 / -1;
}

@media (min-width: 640px) {
  .manual-field-wide {
    grid-column: span 2;
  }
}

.manual-panel .btn-row {
  margin-bottom: 0.35rem;
}

.col-actions {
  width: 4.5rem;
  text-align: center;
  white-space: nowrap;
}

.btn-row-action {
  display: inline-flex;
  gap: 0.25rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 0.8125rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-icon:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.btn-icon-del:hover {
  border-color: #fca5a5;
  color: #dc2626;
  background: #fef2f2;
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1.45;
}

.check-label input {
  margin-top: 0.2rem;
  accent-color: var(--brand);
}

.custom-size-row,
.print-range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  font-size: 0.875rem;
}

.custom-size-row label,
.print-range-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text);
}

/* ── Status & hints ── */
.intro {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.intro-system-print {
  color: var(--brand-dark);
}

.print-hint-box {
  margin: 0 0 1rem;
  padding: 0.875rem 1rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
}

.print-hint-title {
  margin: 0 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: #92400e;
}

.print-hint-text {
  margin: 0;
  font-size: 0.8125rem;
  color: #78350f;
  line-height: 1.55;
}

.print-hint-ios {
  background: #eff6ff;
  border-color: #93c5fd;
}

.print-hint-ios .print-hint-title {
  color: #1e40af;
}

.print-hint-ios .print-hint-text,
.print-hint-list {
  color: #1e3a8a;
}

.print-hint-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.8125rem;
  line-height: 1.6;
}

.print-hint-list li + li {
  margin-top: 0.35rem;
}

.btn-ios {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1e40af;
}

.btn-ios:hover:not(:disabled) {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hint-err {
  color: #dc2626;
}

.hint-inline {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.status {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
}

.status-idle { color: var(--text-muted); }
.status-ok { color: #15803d; background: #f0fdf4; }
.status-err { color: #dc2626; background: #fef2f2; }
.status-busy { color: #a16207; background: #fffbeb; }

.divider {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: 1.25rem 0;
}

/* ── Table ── */
.table-wrap {
  margin-top: 0.875rem;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th,
td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0.02em;
}

tbody tr {
  transition: background 0.12s;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr.active {
  background: var(--brand-light);
}

tbody tr.active td {
  font-weight: 500;
}

tbody tr.editing {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody input[type="checkbox"] {
  accent-color: var(--brand);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* ── Preview ── */
.preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
}

.preview-nav {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  align-items: stretch;
  min-width: 108px;
}

.preview-nav .btn {
  width: 100%;
}

#previewIndex {
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.35rem 0;
}

.label-frame {
  background:
    repeating-conic-gradient(#e2e8f0 0% 25%, #f1f5f9 0% 50%) 50% / 16px 16px;
  padding: 1.25rem;
  border-radius: var(--radius-sm);
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  border: 1px solid var(--border);
}

#previewCanvas {
  width: 100%;
  max-width: 440px;
  height: auto;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
}

/* ── Platform banner ── */
.platform-banner {
  max-width: 1140px;
  margin: 0.75rem auto 0;
  padding: 0 1rem;
}

.platform-banner.warn {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #9a3412;
  box-shadow: var(--shadow-sm);
}

.boot-error {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 0.75rem 1rem;
  background: #dc2626;
  color: #fff;
  font-size: 0.875rem;
  line-height: 1.4;
  text-align: center;
}

/* ── Mobile bar ── */
.mobile-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 0.625rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(12px);
  z-index: 100;
}

.mobile-bar .btn {
  flex: 1;
  padding: 0.8rem 1rem;
  font-size: 0.9375rem;
}

@media (min-width: 768px) {
  .mobile-bar {
    display: none;
  }
}

/* ── Print ── */
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { position: absolute; left: 0; top: 0; }
  .print-pages .label-page {
    width: var(--lw, 70mm);
    height: var(--lh, 50mm);
    page-break-after: always;
  }
  .print-pages .label-page img {
    width: var(--lw, 70mm);
    height: var(--lh, 50mm);
  }
}
