/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg-base: #0d1117;
  --bg-panel: #161b22;
  --bg-glass: rgba(22, 27, 34, 0.85);
  --bg-row-alt: rgba(255, 255, 255, 0.025);
  --bg-row-hover: rgba(56, 189, 248, 0.07);

  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.15);
  --accent-glow: rgba(56, 189, 248, 0.35);
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);

  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.5);

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(56, 189, 248, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 110%, rgba(34, 197, 94, 0.05) 0%, transparent 60%);
}

/* ─── Header ────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 26px;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
  line-height: 1;
}

.site-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.site-subtitle {
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  background: var(--accent-dim);
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

/* ─── Tab Nav ───────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.tab-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.tab-btn:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

/* ─── Main ──────────────────────────────────────────────────── */
.main-content {
  max-width: 1300px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  flex: 1;
  width: 100%;
}

/* ─── Tab Panels ────────────────────────────────────────────── */
.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─── Panels ────────────────────────────────────────────────── */
.panel {
  border-radius: var(--radius-lg);
}

.glass-card {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.panel-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.product-count-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 20px;
}

/* ─── Filters ───────────────────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-top: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* Roll selectors sit in the filter row but are compact */
.roll-filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 130px;
}

/* Pushes roll groups to the right end of the filter row */
.roll-filter-group:first-of-type {
  margin-left: auto;
}

/* Label + Total text line above the FG dropdown */
.fg-select-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}


.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 160px;
  max-width: 280px;
}

.filter-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.filter-icon {
  color: var(--accent);
  font-size: 12px;
}

.filter-input {
  padding: 8px 11px;
  font-size: 13px;
}

/* ─── Form ──────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 120px 100px 100px;
  gap: 16px;
  align-items: start;
}

/* Generate tab: single-column layout so the product dropdown spans full width */
.form-grid-gen {
  grid-template-columns: 1fr;
}

.form-group--wide {
  grid-column: 1 / -1;
}

.form-group--full {
  grid-column: 1 / -1;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.label-hint {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.form-control {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-control.mono {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.3px;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-control:hover:not(:focus) {
  border-color: rgba(255, 255, 255, 0.15);
}

.form-control[readonly] {
  color: var(--text-secondary);
  cursor: default;
}

select.form-control {
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

select.form-control option {
  background: #1c2128;
  color: var(--text-primary);
}


.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  min-height: 16px;
  font-family: var(--font-mono);
}

/* ─── Buttons ───────────────────────────────────────────────── */
.action-row,
.lib-action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lib-action-row {
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  outline: none;
  text-decoration: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-icon {
  font-size: 11px;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: #7dd3fc;
  box-shadow: 0 0 22px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: var(--text-muted);
  border-color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
  color: var(--bg-base);
  opacity: 0.5;
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.3);
}

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

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

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

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-active {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  background: rgba(56, 189, 248, 0.08) !important;
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: var(--red-dim);
  border-color: var(--red);
}

/* ─── Stats ─────────────────────────────────────────────────── */
.action-row {
  margin-top: 20px;
}

.stats-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
}

.stat-chip {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
}

.stat-chip.valid {
  color: var(--green);
  border-color: rgba(34, 197, 94, 0.3);
  background: var(--green-dim);
}

.stat-chip.invalid {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
  background: var(--red-dim);
}

/* ─── Validator ─────────────────────────────────────────────── */
.validator-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.validate-result {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
}

.validate-result.ok {
  background: var(--green-dim);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac;
}

.validate-result.fail {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

.validate-result .vr-row {
  display: flex;
  gap: 8px;
}

.validate-result .vr-label {
  color: inherit;
  opacity: 0.6;
  min-width: 140px;
}

.validate-result .vr-val {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
}

/* ─── Results header ────────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 0 0 14px 0;
  border-bottom: 1px solid var(--border);
}

.results-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ─── Tables ────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.code-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.code-table thead {
  background: rgba(255, 255, 255, 0.04);
  position: sticky;
  top: 0;
}

.code-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.th-actions {
  text-align: right;
}

.col-hint {
  display: block;
  font-size: 9px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}

.code-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

.code-table tbody tr:nth-child(even) {
  background: var(--bg-row-alt);
}

.code-table tbody tr:hover {
  background: var(--bg-row-hover);
}

.code-table tbody tr {
  animation: rowIn 0.15s ease both;
}

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Code table specific cells */
.td-num {
  color: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-mono);
}

.td-sgtin {
  color: var(--accent);
  font-family: var(--font-mono);
}

.td-dm {
  color: #c9d1d9;
  font-family: var(--font-mono);
}

.td-serial {
  color: #a5d6a7;
  font-family: var(--font-mono);
}

/* Library table specific */
.lib-table td {
  font-size: 12.5px;
}

.lib-table .td-mono {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
}

.lib-table .td-fg {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

/* Constrain first 3 columns (FG#, Sleeve#, Ningbo Item) to same width */
.lib-table th:nth-child(1),
.lib-table td:nth-child(1),
.lib-table th:nth-child(2),
.lib-table td:nth-child(2),
.lib-table th:nth-child(3),
.lib-table td:nth-child(3) {
  width: 130px;
  max-width: 160px;
}

.td-actions {
  text-align: right;
  white-space: nowrap;
}

/* Archived product rows */
.archived-row {
  opacity: 0.45;
  background: repeating-linear-gradient(-45deg,
      transparent, transparent 8px,
      rgba(255, 255, 255, 0.02) 8px, rgba(255, 255, 255, 0.02) 16px);
}

.archived-row .td-fg {
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.3);
}

/* Badges */
.badge-valid {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  color: var(--green);
  background: var(--green-dim);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-invalid {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.3);
  cursor: help;
}

.badge-pending {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ─── Library toolbar extras ────────────────────────────────── */

.lib-search-row {
  margin-top: 14px;
}

.lib-search-row .form-control {
  max-width: 460px;
}

.import-feedback {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

.import-feedback.ok {
  background: var(--green-dim);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac;
}

.import-feedback.warn {
  background: var(--amber-dim);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fcd34d;
}

.import-feedback.fail {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

/* ─── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 18px 24px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-group--wide {
    grid-column: 1 / -1;
  }

  .header-right {
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
  }
}

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

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

  .filter-row {
    flex-direction: column;
  }

  .filter-group {
    max-width: 100%;
  }

  .validator-row {
    flex-direction: column;
    align-items: stretch;
  }

  .lib-action-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ─── Generating shimmer ────────────────────────────────────── */
.generating {
  position: relative;
  overflow: hidden;
}

.generating::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.05), transparent);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

/* ─── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.empty-state-icon {
  font-size: 32px;
  margin-bottom: 10px;
  opacity: 0.4;
}

/* ─── Product Meta Bar ──────────────────────────────────────── */
.product-meta-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  margin-bottom: 4px;
}

.meta-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 20px;
  padding: 4px 12px 4px 10px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.meta-val {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 500;
}

.meta-val.mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ─── Results Area split layout ─────────────────────────────── */
#results-area {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.label-preview-pane {
  flex: 0 0 300px;
  min-width: 280px;
  position: sticky;
  top: 70px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.results-panel-inner {
  flex: 1;
  min-width: 0;
}

.lp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.lp-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.lp-sub {
  font-size: 11px;
  color: var(--accent);
  font-family: var(--font-mono);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 20px;
}

/* ─── Physical Label Card — exact 53×19mm ratio ─────────────── */
.label-card {
  background: #ffffff;
  border-radius: 3px;
  display: flex;
  align-items: stretch;
  /* Exact physical label proportions: 53mm wide × 19mm tall */
  aspect-ratio: 53 / 19;
  width: 100%;
  padding: 7px 0 7px 6px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  margin-bottom: 16px;
  gap: 0;
  overflow: hidden;
}

.label-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  /* keep logo pinned left */
  justify-content: center;
  gap: 5px;
  padding: 0 6px 0 4px;
  flex: 1 1 auto;
  /* stretch to fill gap, pushing DataMatrix + sleeve to the right */
  min-width: 68px;
}

.transparency-logo {
  width: 52px;
  height: auto;
  display: block;
  image-rendering: crisp-edges;
}

.label-scan-text {
  font-size: 6.5px;
  color: #111;
  text-align: center;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.35;
  font-weight: 400;
  white-space: nowrap;
}

.label-divider {
  display: none;
}

/* Center column: Datamatrix canvas */
.label-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px 0 0;
  flex: 0 0 auto;
}

.dm-canvas {
  display: block;
  image-rendering: pixelated;
  width: 82px;
  height: 82px;
  border-radius: 1px;
}

/* Right column: sleeve # rotated vertical (bottom-to-top) */
.label-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 4px;
  flex: 0 0 20px;
  overflow: visible;
}

.label-sleeve {
  transform: rotate(-90deg);
  transform-origin: center center;
  font-size: 12px;
  color: #222;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0.4px;
  white-space: nowrap;
  line-height: 1;
  user-select: all;
  font-weight: 600;
}

/* ─── Label Preview Details ──────────────────────────────────── */
.lp-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lp-detail-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.lp-dl {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.lp-dv {
  font-size: 11px;
  color: var(--text-primary);
  word-break: break-all;
  line-height: 1.4;
}

.lp-dv.mono {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--accent);
}

/* ─── Row selected state ─────────────────────────────────────── */
.code-table tbody tr.row-selected {
  background: rgba(56, 189, 248, 0.12) !important;
  outline: 1px solid rgba(56, 189, 248, 0.3);
  outline-offset: -1px;
}

.code-table tbody tr {
  cursor: pointer;
}

/* Results hint text */
.results-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  font-style: italic;
}

/* ─── Responsive: stack label preview above table on narrow ─── */
@media (max-width: 1000px) {
  #results-area {
    flex-direction: column;
  }

  .label-preview-pane {
    flex: none;
    width: 100%;
    position: static;
  }

  .label-card {
    max-width: 320px;
    margin: 0 auto 16px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   AUTH OVERLAY
   ═══════════════════════════════════════════════════════════════ */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 36px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.auth-logo-img {
  width: 48px;
  height: auto;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}

.auth-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.auth-brand-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
}

.auth-error {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

.auth-pw-wrap {
  position: relative;
}

.auth-pw-wrap .form-control {
  padding-right: 42px;
}

.auth-pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  opacity: 0.6;
  color: var(--text-primary);
  padding: 4px;
}

.auth-pw-toggle:hover {
  opacity: 1;
}

.auth-forgot {
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: underline;
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════
   HEADER USER AREA
   ═══════════════════════════════════════════════════════════════ */
.header-user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
}

.header-user-email {
  font-size: 11px;
  color: var(--text-secondary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-role-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Role badge colors ─────────────────────────────────────── */
.role-admin {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.35);
}

.role-manager {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.role-user {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ─── Week badge (auto, read-only) ──────────────────────────── */
.week-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.2);
  color: var(--accent);
  border-radius: 20px;
  margin-left: auto;
  cursor: default;
  user-select: none;
}

/* ═══════════════════════════════════════════════════════════════
   DEDUP STATUS BAR
   ═══════════════════════════════════════════════════════════════ */
.dedup-status {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 10px;
  border: 1px solid transparent;
}

.dedup-status.checking {
  background: var(--accent-dim);
  border-color: rgba(56, 189, 248, 0.25);
  color: var(--accent);
}

.dedup-status.ok {
  background: var(--green-dim);
  border-color: rgba(34, 197, 94, 0.25);
  color: var(--green);
}

.dedup-status.warn {
  background: var(--amber-dim);
  border-color: rgba(245, 158, 11, 0.25);
  color: var(--amber);
}

/* ═══════════════════════════════════════════════════════════════
   GENERATE FORM GRID (no year/week inputs)
   ═══════════════════════════════════════════════════════════════ */
.form-grid-gen {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 700px) {
  .form-grid-gen {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════════
   ADMIN PANEL
   ═══════════════════════════════════════════════════════════════ */
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.admin-add-form {
  padding: 20px;
  margin-bottom: 16px;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 16px;
}

.admin-form-notice {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 10px;
  font-style: italic;
}

.admin-add-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 8px;
  background: var(--red-dim);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.domain-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
}

.admin-table-wrap {
  border-radius: var(--radius);
  overflow: hidden;
}

.text-muted {
  color: var(--text-muted);
}

.inline-select-wrap {
  display: inline-block;
  margin-right: 6px;
}

/* Inline role select — styled like btn-secondary */
.inline-select-wrap select.form-control {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}

.inline-select-wrap select.form-control:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.inline-select-wrap.custom-select-wrap::after {
  color: var(--accent);
}

.form-control-sm {
  padding: 4px 8px;
  font-size: 12px;
  height: auto;
}

/* Remove spinner arrows from all number inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* ═══════════════════════════════════════════════════════════════
   HISTORY TAB
   ═══════════════════════════════════════════════════════════════ */
.history-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.history-row {
  cursor: default;
}

.history-detail-row td {
  padding: 0 !important;
  background: rgba(0, 0, 0, 0.2);
  border-top: none !important;
}

.history-detail-cell {
  padding: 0 !important;
}

.history-codes-wrap {
  padding: 12px 24px 16px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 11px;
}

.sort-arrow {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════ */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  transition: opacity 0.5s;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.toast-ok {
  background: var(--green);
  color: #0a2e17;
}

.toast-error {
  background: var(--red);
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════
   CUSTOM SELECT ARROW (site-styled)
   ═══════════════════════════════════════════════════════════════ */
.custom-select-wrap {
  position: relative;
}

.custom-select-wrap::after {
  content: '▾';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 12px;
}

.custom-select-wrap select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 28px;
  cursor: pointer;
}

/* ─── Danger button ──────────────────────────────────────────── */
.btn-danger {
  background: var(--red-dim);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
}

/* ═══════════════════════════════════════════════════════════════
   SELECT DARK THEME — full site-native styling
   ═══════════════════════════════════════════════════════════════ */

/* Wrapper: arrow + contained select height */
.custom-select-wrap {
  position: relative;
  display: block;
}

.custom-select-wrap::after {
  content: '\25BE';
  /* ▾ */
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--accent);
  font-size: 13px;
  transition: color 0.15s;
}

/* Hide the CSS arrow when JS custom dropdown is active (has its own arrow) */
.custom-select-wrap:has(.cselect-btn)::after {
  display: none;
}

.custom-select-wrap:focus-within::after {
  color: var(--accent);
}

.custom-select-wrap select {
  width: 100%;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 32px;
  cursor: pointer;
}

/* Select base */
select.form-control {
  background-color: var(--bg-panel);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select.form-control:hover {
  border-color: rgba(56, 189, 248, 0.3);
}

select.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.12);
  color: var(--text-primary);
  background-color: var(--bg-panel);
}

/* Chromium supports styling options directly */
select.form-control option {
  background-color: #1c2128;
  color: var(--text-primary);
  padding: 6px 10px;
}

select.form-control option:hover {
  background-color: var(--accent-dim);
  color: var(--accent);
}

select.form-control option:checked,
select.form-control option:checked:hover {
  background-color: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* ─── Library History section ────────────────────────────────── */

/* When lib-admin-actions span is shown by JS (display:''), it acts as
   display:contents so its buttons flow inline in the parent flex row */
#lib-admin-actions {
  display: contents;
}

/* ─── Generate tab dropdown accent styling ───────────────────── */
/* Override the dark-default select style with btn-secondary accent look */
#panel-generate .custom-select-wrap select.form-control,
.roll-filter-group .custom-select-wrap select.form-control {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-weight: 600;
}

#panel-generate .custom-select-wrap select.form-control:hover,
.roll-filter-group .custom-select-wrap select.form-control:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

#panel-generate .custom-select-wrap::after,
.roll-filter-group .custom-select-wrap::after {
  color: var(--accent);
}

/* Accent styling for custom JS dropdown buttons on generate tab */
#panel-generate .cselect-btn,
.roll-filter-group .cselect-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-weight: 600;
}

#panel-generate .cselect-btn:hover,
.roll-filter-group .cselect-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.lib-history-section {
  margin-top: 12px;
}

.lib-history-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.lib-history-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.lib-history-arrow {
  font-size: 11px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.lib-history-arrow.open {
  display: inline-block;
  transform: rotate(90deg);
}

/* ═══════════════════════════════════════════════════════════════
   VALIDATE TAB — IMAGE SCAN
   ═══════════════════════════════════════════════════════════════ */
.scan-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 4px;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 4px;
}

.scan-upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.scan-upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 20px;
  cursor: pointer;
  border-radius: calc(var(--radius) - 4px);
  transition: background 0.2s;
}

.scan-upload-label:hover {
  background: rgba(255, 255, 255, 0.03);
}

.scan-upload-icon {
  font-size: 32px;
  opacity: 0.5;
}

.scan-upload-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.scan-upload-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.scan-preview-img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  margin: 8px auto;
  border-radius: var(--radius-sm);
  object-fit: contain;
  border: 1px solid var(--border);
}

.scan-preview-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 8px 0 4px;
}

.scan-status {
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  border: 1px solid transparent;
  text-align: center;
}

.scan-status.checking {
  background: var(--accent-dim);
  border-color: rgba(56, 189, 248, 0.25);
  color: var(--accent);
}

.scan-status.ok {
  background: var(--green-dim);
  border-color: rgba(34, 197, 94, 0.25);
  color: var(--green);
}

.scan-status.fail {
  background: var(--red-dim);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--red);
}

/* Or divider */
.validate-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 14px;
  color: var(--text-muted);
  font-size: 11px;
}

.validate-divider::before,
.validate-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Roll Quantity Selectors ────────────────────────────────── */
.roll-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  /* span full form-grid width */
}

.roll-qty-group {
  flex: 0 0 auto;
  min-width: 160px;
}

.roll-total-inline {
  flex: 1;
  text-align: right;
  font-size: 12px;
  color: var(--text-secondary);
  padding-bottom: 9px;
  /* align with select bottom edge */
  white-space: nowrap;
}

.roll-total-inline span {
  font-weight: 600;
  color: var(--text-primary);
}


/* ─── Admin Roll Config row/input ────────────────────────────── */
.roll-cfg-sizes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.roll-cfg-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Custom Role Dropdown ───────────────────────────────────── */

/* Allow role dropdown to overflow the admin table scroll wrapper */
.admin-table-wrap {
  overflow: visible;
}

.role-dropdown {
  position: relative;
  display: inline-block;
}

.role-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-width: 96px;
  justify-content: space-between;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--font-sans);
}

.role-dropdown-btn:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.role-dropdown-btn .rdrop-arrow {
  font-size: 10px;
  opacity: 0.7;
}

.role-dropdown-menu {
  position: fixed;
  min-width: 120px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 9999;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: none;
}

.role-dropdown-menu.open {
  display: block;
}

.role-dropdown-item {
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: background 0.1s, color 0.1s;
}

.role-dropdown-item:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.role-dropdown-item.selected {
  color: var(--accent);
  font-weight: 600;
  background: rgba(56, 189, 248, 0.06);
}

/* ═══════════════════════════════════════════════════════════════
   CUSTOM SELECT COMPONENT  (.cselect-*)
   ═══════════════════════════════════════════════════════════════ */
.cselect-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  line-height: normal;
  font-family: var(--font-sans);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  box-sizing: border-box;
}

.cselect-btn:hover {
  border-color: var(--accent);
  background: var(--bg-hover, rgba(255, 255, 255, 0.04));
}

.cselect-btn:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.cselect-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 8px;
}

.cselect-arrow {
  font-size: 11px;
  color: var(--accent);
  flex-shrink: 0;
}

/* Menu — absolute to parent .custom-select-wrap (which is position:relative) */
.cselect-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin-top: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 9999;
  display: none;
  overflow-y: auto;
  max-height: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE/Edge */
}

.cselect-menu::-webkit-scrollbar {
  display: none;
  /* Chrome/Safari */
}

.cselect-menu.open {
  display: block;
}

.cselect-item {
  padding: 9px 14px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s, color 0.1s;
}

.cselect-item:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.cselect-item.selected {
  color: var(--accent);
  font-weight: 600;
  background: rgba(56, 189, 248, 0.07);
}