:root {
  --canvas: #0a0a0a;
  --surface-soft: #121212;
  --surface-card: #1a1a1a;
  --surface-elevated: #242424;
  --primary: #faff69;
  --primary-active: #e6eb52;
  --primary-disabled: #3a3a1f;
  --ink: #ffffff;
  --body: #cccccc;
  --muted: #888888;
  --hairline: #2a2a2a;
  --hairline-strong: #3a3a3a;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --paper: #ffffff;
  --paper-ink: #050505;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "DejaVu Sans Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }

button { color: inherit; }

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--canvas);
  font-weight: 700;
}

.skip-link:focus { top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--hairline);
  background: rgba(10, 10, 10, 0.97);
}

.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: -0.2px; }

.brand-mark { display: flex; align-items: end; gap: 2px; width: 30px; height: 24px; }
.brand-mark i { display: block; width: 2px; background: var(--primary); }
.brand-mark i:nth-child(1), .brand-mark i:nth-child(7) { height: 12px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(6) { width: 4px; height: 20px; }
.brand-mark i:nth-child(3), .brand-mark i:nth-child(5) { height: 16px; }
.brand-mark i:nth-child(4) { width: 5px; height: 24px; }

.tabs { display: flex; gap: 4px; min-width: 0; }

.tab {
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.tab:hover { color: var(--ink); background: var(--surface-soft); }
.tab.is-active { color: var(--ink); background: var(--surface-card); }

.system-status { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.13); }

.workspace { width: 100%; min-width: 0; min-height: calc(100vh - 65px); padding: 32px; }
.tab-panel { max-width: 1500px; margin: 0 auto; min-width: 0; }
.tab-panel[hidden] { display: none; }

.generate-layout { display: grid; grid-template-columns: minmax(0, 1.18fr) minmax(360px, 0.82fr); gap: 32px; align-items: start; }
.control-column, .live-column { min-width: 0; }

.section-heading, .preview-toolbar, .live-header, .batches-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.section-heading { margin-bottom: 24px; }
.section-heading h1, .preview-toolbar h1, .settings-layout h1 { margin: 3px 0 0; font-size: clamp(26px, 3vw, 40px); line-height: 1.15; letter-spacing: -1px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; }
.format-badge { padding: 5px 10px; border-radius: 999px; background: var(--primary); color: var(--canvas); font-family: var(--font-mono); font-size: 11px; font-weight: 700; }

.panel { border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface-card); }
.form-panel { padding: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.form-grid-four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; min-width: 0; margin-bottom: 20px; color: var(--body); font-size: 12px; font-weight: 600; }
.field-wide { width: 100%; }
.field label, label.field { color: var(--body); }

input, textarea {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--hairline-strong);
  border-radius: 8px;
  outline: none;
  background: var(--surface-elevated);
  color: var(--ink);
  font-family: var(--font-mono);
}

input { min-height: 42px; padding: 9px 12px; }
textarea { min-height: 76px; padding: 10px 12px; resize: vertical; font-family: var(--font-sans); }
input:hover, textarea:hover { border-color: #555555; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(250, 255, 105, 0.12); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12); }

.field-help, .field-error { min-height: 17px; margin: 5px 0 0; font-size: 11px; font-weight: 400; }
.field-help { color: var(--muted); }
.field-error { color: #ff8585; }

.form-actions { display: flex; justify-content: flex-end; gap: 12px; padding-top: 4px; }
.button { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 10px 18px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 700; white-space: nowrap; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:focus-visible, .tab:focus-visible { outline: 3px solid rgba(250, 255, 105, 0.55); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; transform: none; opacity: 0.55; }
.button-primary { background: var(--primary); color: var(--canvas); }
.button-primary:hover { background: #ffff8f; }
.button-primary:active { background: var(--primary-active); }
.button-secondary { border-color: var(--hairline-strong); background: var(--surface-elevated); color: var(--ink); }
.button-secondary:hover { border-color: #555555; background: #2c2c2c; }
.button-icon { min-width: 42px; padding: 8px; font-size: 18px; }
.button-spinner { display: none; width: 14px; height: 14px; border: 2px solid rgba(10, 10, 10, 0.35); border-top-color: var(--canvas); border-radius: 50%; animation: spin 0.7s linear infinite; }
.button.is-loading .button-spinner { display: inline-block; }
.button.is-loading { cursor: wait; }

.live-column { position: sticky; top: 96px; padding-top: 8px; }
.live-header { margin-bottom: 14px; }
.validation-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.validation-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.validation-state.is-valid { color: var(--success); }
.validation-state.is-invalid { color: var(--error); }
.validation-state.is-checking { color: var(--warning); }

.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.metric-card { min-width: 0; min-height: 112px; padding: 16px; border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface-card); }
.metric-card span, .identifier-label, .capacity-line span { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.metric-card strong { display: block; margin-top: 18px; overflow: hidden; font-size: clamp(23px, 3vw, 35px); line-height: 1; letter-spacing: -1px; text-overflow: ellipsis; }
.metric-primary { background: var(--primary); color: var(--canvas); border-color: var(--primary); }
.metric-primary span { color: rgba(10, 10, 10, 0.65); }

.identifier-card { position: relative; overflow: hidden; margin-top: 12px; padding: 20px; border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface-card); }
.identifier-card code { position: relative; z-index: 1; display: block; margin: 5px 0 24px; overflow-wrap: anywhere; color: var(--ink); font-family: var(--font-mono); font-size: clamp(17px, 2vw, 24px); font-weight: 700; }
.identifier-card code:last-child { margin-bottom: 0; }
.barcode-stripes { height: 46px; margin: 2px -20px 18px; opacity: 0.17; background: repeating-linear-gradient(90deg, var(--primary) 0 2px, transparent 2px 5px, var(--primary) 5px 6px, transparent 6px 10px); }
.capacity-line { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 14px 16px; border-top: 1px solid var(--hairline); }
.capacity-line strong { color: var(--primary); font-family: var(--font-mono); }

.message { margin: 12px 0; padding: 11px 13px; border: 1px solid var(--hairline-strong); border-radius: 8px; background: var(--surface-elevated); color: var(--body); }
.message-error { border-color: rgba(239, 68, 68, 0.6); color: #ff9a9a; }
.message-success { border-color: rgba(34, 197, 94, 0.55); color: #7ee7a4; }
.message-warning { border-color: rgba(245, 158, 11, 0.55); color: #fbc76b; }

.preview-toolbar { margin-bottom: 18px; }
.toolbar-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.page-jump { display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 10px; border: 1px solid var(--hairline-strong); border-radius: 8px; background: var(--surface-card); color: var(--muted); font-size: 12px; font-weight: 700; }
.page-jump input { width: 62px; min-height: 30px; height: 30px; margin: 0; padding: 3px 6px; text-align: center; }

.paper-stage { min-height: calc(100vh - 180px); overflow: auto; padding: 28px; border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface-soft); }
.a4-sheet { width: min(100%, 794px); aspect-ratio: 210 / 297; min-width: 620px; margin: 0 auto; padding: 2.14%; background: var(--paper); color: var(--paper-ink); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.42); }
.label-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(16, minmax(0, 1fr)); width: 100%; height: 100%; border-top: 1px solid #c7c7c7; border-left: 1px solid #c7c7c7; }
.label-slot { position: relative; display: flex; min-width: 0; min-height: 0; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; border-right: 1px solid #c7c7c7; border-bottom: 1px solid #c7c7c7; background: #fff; }
.label-slot img { display: block; width: 88%; height: 58%; object-fit: fill; }
.label-slot code { width: 94%; overflow: hidden; color: #000; font: 600 clamp(5px, 0.72vw, 9px)/1.15 Arial, sans-serif; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.label-slot.is-empty { background: repeating-linear-gradient(135deg, #fff 0 6px, #fafafa 6px 12px); }
.slot-number { position: absolute; left: 3px; top: 2px; color: #b0b0b0; font: 600 6px/1 var(--font-mono); }

.search-field { display: grid; grid-template-columns: auto minmax(220px, 340px); align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.search-field input { margin: 0; }
.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; border: 1px solid var(--hairline); border-radius: 12px; background: var(--surface-card); }
.summary-strip div { display: flex; align-items: baseline; justify-content: space-between; min-width: 0; padding: 16px 20px; border-right: 1px solid var(--hairline); }
.summary-strip div:last-child { border-right: 0; }
.summary-strip span { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.summary-strip strong { color: var(--primary); font: 700 24px/1 var(--font-mono); }
.table-panel { min-width: 0; overflow: hidden; }
.table-scroll { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--hairline); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-elevated); color: var(--muted); font-size: 10px; letter-spacing: 1.1px; text-transform: uppercase; }
td { color: var(--body); }
td strong { display: block; color: var(--ink); }
td code { font-family: var(--font-mono); font-size: 12px; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.row-action { min-height: 34px; padding: 6px 10px; }
.source-tag { display: inline-block; margin-top: 4px; color: var(--primary); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.empty-state { display: flex; min-height: 180px; flex-direction: column; align-items: center; justify-content: center; gap: 5px; color: var(--muted); }
.empty-state strong { color: var(--ink); }

.settings-layout { display: grid; grid-template-columns: minmax(260px, 0.55fr) minmax(620px, 1.45fr); gap: 40px; align-items: start; }
.section-copy { max-width: 48ch; color: var(--body); }
.settings-group { padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--hairline); }
.settings-group h2 { margin: 0 0 14px; font-size: 15px; }
.settings-group h2 span { color: var(--muted); font-size: 11px; font-weight: 500; }
.settings-group .field { margin-bottom: 0; }
.check-field { display: flex; min-height: 69px; align-items: center; gap: 10px; align-self: end; padding: 8px 10px; border: 1px solid var(--hairline-strong); border-radius: 8px; background: var(--surface-elevated); color: var(--body); font-weight: 600; }
.check-field input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--primary); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(420px, calc(100vw - 48px)); padding: 13px 16px; border: 1px solid var(--hairline-strong); border-radius: 8px; background: var(--surface-elevated); color: var(--ink); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: auto 1fr; }
  .tabs { justify-self: end; }
  .system-status { display: none; }
  .generate-layout, .settings-layout { grid-template-columns: 1fr; }
  .live-column { position: static; }
  .settings-layout .form-panel { min-width: 0; }
}

@media (max-width: 760px) {
  .topbar { position: static; display: flex; flex-wrap: wrap; padding: 12px 16px; }
  .brand { width: 100%; height: 38px; }
  .tabs { width: 100%; overflow-x: auto; }
  .tab { flex: 0 0 auto; }
  .workspace { min-height: 0; padding: 20px 14px; }
  .form-grid, .form-grid-four { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric-card:first-child { grid-column: 1 / -1; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .preview-toolbar, .batches-heading { align-items: stretch; flex-direction: column; }
  .toolbar-actions { justify-content: flex-start; }
  .toolbar-actions .button:not(.button-icon) { flex: 1 1 160px; }
  .paper-stage { padding: 12px; }
  .a4-sheet { min-width: 560px; }
  .search-field { grid-template-columns: 1fr; }
  .summary-strip { grid-template-columns: 1fr; }
  .summary-strip div { border-right: 0; border-bottom: 1px solid var(--hairline); }
  .summary-strip div:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

