:root {
  --bg-desk: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --border-line: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --brand-blue: #2563eb;
  --brand-blue-hover: #1d4ed8;
  --brand-blue-soft: #eff6ff;
  --crop-red: #dc2626;
  --amber-bg: #fffbeb;
  --amber-border: #f59e0b;
  --amber-text: #92400e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-desk);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'SF Pro Text', 'Segoe UI', 'PingFang SC', sans-serif;
  font-size: 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Strictly Single-Row 48px Topbar — Zero Horizontal Scrollbar */
.topbar {
  height: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-line);
  flex-wrap: nowrap;
  overflow: hidden;
}

.topbar-left,
.topbar-center,
.topbar-right,
.work-only {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-left,
.topbar-right {
  flex-shrink: 0;
}

.topbar-center {
  flex-shrink: 1;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 2px;
}

.brand-icon {
  border-radius: 5px;
}

.brand-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.compact-select {
  height: 30px;
  max-width: 190px;
  background: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.compact-select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--brand-blue);
}

.custom-size-box {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 2px 5px;
  height: 30px;
}

.custom-size-box input {
  width: 44px;
  border: 1px solid var(--border-line);
  border-radius: 4px;
  padding: 2px 3px;
  font-size: 12px;
  text-align: center;
}

.custom-size-box select {
  border: none;
  background: transparent;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.mixed-tabs {
  display: inline-flex;
  background: var(--bg-desk);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-line);
  flex-shrink: 0;
}

.mixed-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 3.5px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.mixed-tab.active {
  background: var(--bg-surface);
  color: var(--brand-blue);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.sep-check-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Buttons & Quiet Understated Feedback Button */
.btn-primary,
.btn-secondary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-compact {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-xs {
  height: 24px;
  padding: 0 8px;
  font-size: 11.5px;
}

.btn-lg {
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
  padding: 9px 14px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--brand-blue);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-blue-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: #94a3b8;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-line);
}

.btn-ghost:hover {
  background: var(--bg-desk);
  color: var(--text-primary);
}

/* Understated, readable text button — never competes with Print CTA */
.feedback-quiet-btn {
  height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.feedback-quiet-btn:hover {
  background: var(--bg-desk);
  color: var(--text-primary);
}

.lang-switch {
  display: inline-flex;
  background: var(--bg-desk);
  border: 1px solid var(--border-line);
  border-radius: 6px;
  padding: 2px;
  height: 30px;
  align-items: center;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Main Workbench & Empty Card */
.workbench {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.workbench.drag-over::after {
  content: attr(data-drop-label);
  position: absolute;
  inset: 14px;
  background: rgba(239, 246, 255, 0.94);
  border: 2px dashed var(--brand-blue);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--brand-blue);
  z-index: 40;
  pointer-events: none;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.empty-card {
  max-width: 480px;
  width: 100%;
  background: var(--bg-surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: 16px;
  padding: 40px 32px 30px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.03);
}

.empty-illus {
  margin-bottom: 12px;
}

.empty-card h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.empty-card p {
  color: var(--text-secondary);
  margin: 0 0 22px;
  font-size: 13px;
  line-height: 1.55;
}

.empty-local-note {
  margin-top: 20px;
  font-size: 11.5px;
  color: #94a3b8;
}

/* 100% Full-Viewport Thermal Output Grid */
.grid-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.grid-subbar {
  height: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-line);
}

.grid-summary-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.file-chips-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 68vw;
  scrollbar-width: none;
}

.file-chips-row::-webkit-scrollbar {
  display: none;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: 999px;
  padding: 2px 4px 2px 9px;
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.file-chip button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.file-chip button:hover {
  background: #fee2e2;
  color: var(--crop-red);
}

.label-grid {
  flex: 1;
  overflow-y: scroll;
  padding: 20px 20px 44px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(226px, 1fr));
  gap: 16px;
  align-content: start;
}

.label-grid.sku-grid {
  grid-template-columns: repeat(auto-fill, minmax(204px, 1fr));
}

.grid-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 12px 12px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.05);
  position: relative;
}

.grid-card:hover {
  border-color: #93c5fd;
}

.grid-card.warn-card {
  border: 1.5px solid var(--amber-border);
  background: #fffdf5;
}

.grid-card.is-skipped {
  background: #f8fafc;
  border: 1.5px dashed #cbd5e1;
  box-shadow: none;
}

.card-paper-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px;
  position: relative;
  min-height: 104px;
}

.card-paper-wrap canvas {
  max-width: 100%;
  height: auto;
  display: block;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

.grid-card.is-skipped .card-paper-wrap canvas {
  opacity: 0.28;
  filter: grayscale(1);
}

.skipped-restore-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.skipped-tag {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.restore-pill-btn {
  background: var(--bg-surface);
  color: var(--brand-blue);
  border: 1px solid #93c5fd;
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.restore-pill-btn:hover {
  background: var(--brand-blue);
  color: #ffffff;
}

.card-qz-bar {
  width: 100%;
  margin-top: 7px;
  padding: 4px 7px;
  background: var(--amber-bg);
  border: 1px solid #fcd34d;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--amber-text);
}

.card-qz-bar button {
  background: #d97706;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.card-qz-bar button:hover {
  background: #b45309;
}

.card-footer {
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.card-num {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.card-act-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-line);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 2px 6.5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.card-act-btn:hover {
  background: var(--brand-blue-soft);
  border-color: #93c5fd;
  color: var(--brand-blue);
}

.card-act-btn.danger:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: var(--crop-red);
}

/* On-Demand Slide-Over Crop Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  justify-content: flex-end;
  z-index: 80;
}

.crop-drawer {
  width: min(640px, 94vw);
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-line);
  box-shadow: -16px 0 44px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
}

.drawer-header {
  height: 50px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-toolbar {
  padding: 8px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-line);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.drawer-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.drawer-stage-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 22px;
  background-color: #e8eef5;
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 16px 16px;
}

.source-stage {
  position: relative;
  background: #ffffff;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.14);
  user-select: none;
}

#source-canvas {
  display: block;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--crop-red);
  background: rgba(220, 38, 38, 0.05);
  cursor: move;
  pointer-events: auto;
}

.crop-box.inactive {
  border-color: rgba(100, 116, 139, 0.45);
  border-style: dashed;
  background: transparent;
  cursor: pointer;
}

.crop-box.active {
  border-color: var(--brand-blue);
  border-width: 2px;
  background: rgba(37, 99, 235, 0.07);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.18);
  z-index: 3;
}

.crop-badge {
  position: absolute;
  left: -2px;
  top: -21px;
  background: #64748b;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 4px 4px 4px 0;
  white-space: nowrap;
  pointer-events: none;
}

.crop-box.active .crop-badge {
  background: var(--brand-blue);
}

.crop-rotate-btn {
  position: absolute;
  right: 5px;
  top: 5px;
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  border: none;
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  z-index: 4;
}

.crop-rotate-btn:hover {
  background: var(--brand-blue);
}

.crop-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #ffffff;
  border: 2px solid var(--brand-blue);
  border-radius: 2px;
  z-index: 5;
}

.crop-handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.crop-handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.crop-handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.crop-handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.crop-handle.n  { left: calc(50% - 7px); top: -4px; width: 14px; height: 7px; cursor: ns-resize; }
.crop-handle.s  { left: calc(50% - 7px); bottom: -4px; width: 14px; height: 7px; cursor: ns-resize; }
.crop-handle.w  { left: -4px; top: calc(50% - 7px); width: 7px; height: 14px; cursor: ew-resize; }
.crop-handle.e  { right: -4px; top: calc(50% - 7px); width: 7px; height: 14px; cursor: ew-resize; }

.drawer-footer-hint {
  padding: 8px 16px;
  border-top: 1px solid var(--border-line);
  background: var(--bg-surface);
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

/* Understated Feedback Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  max-width: 420px;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-line);
  border-radius: 14px;
  padding: 24px;
  position: relative;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
}

.modal-close {
  position: absolute;
  right: 14px;
  top: 14px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}

.modal-desc {
  color: var(--text-secondary);
  margin: 0 0 14px;
  line-height: 1.5;
  font-size: 12.5px;
}

.fb-email-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 8px 7px 12px;
  margin-bottom: 10px;
}

.fb-email-box code {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  user-select: all;
}

.print-frame {
  position: fixed;
  width: 0;
  height: 0;
  border: 0;
  visibility: hidden;
}

.hidden {
  display: none !important;
}
