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

:root {
  --dark:   #252525;
  --blue:   #005ae1;
  --blue-h: #0048b8;
  --mid:    #474747;
  --light:  #f7f9fd;
  --white:  #ffffff;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--light) url('/static/images/table_top.jpg') center center / cover no-repeat fixed;
  color: var(--dark);
  min-height: 100vh;
  padding: 0;
}

/* ── Top navigation bar ─────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 64px;
  background: var(--white);
  border-bottom: 1px solid #e8e8e8;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 1rem;
  font-weight: 800;
  color: var(--dark);
  letter-spacing: -0.3px;
  text-decoration: none;
}
.topbar-logo {
  height: 34px;
  width: auto;
  flex-shrink: 0;
  border-radius: 4px;
}

.topbar-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.topbar-link {
  background: none;
  border: none;
  color: var(--mid);
  font-size: 0.85rem;
  font-family: inherit;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.topbar-link:hover {
  background: var(--light);
  color: var(--dark);
}

/* ── Modals ─────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
  z-index: 201;
  width: min(520px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem 0.75rem;
  border-bottom: 1px solid #f0f0e8;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a1a;
}

.modal-close {
  background: none;
  border: none;
  font-size: 0.85rem;
  color: #888;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: #f0f0e8;
  color: #1a1a1a;
}

.modal-body {
  padding: 1rem 1.4rem 1.4rem;
  font-size: 0.9rem;
  color: #444;
  line-height: 1.6;
}

/* ── Two-column layout ──────────────────────────────────────────────────── */

.layout {
  display: flex;
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  align-items: flex-start;
  padding: 1.5rem;
}

/* Left sidebar: controls */
.options-panel {
  width: 380px;
  flex-shrink: 0;
  transition: width 0.2s ease;
}

/* Right main area: preview */
.preview-panel {
  flex: 1;
  min-width: 0;
}

/* Stage 3 review mode: both panels fill the viewport and scroll independently */
.layout.review-mode {
  height: calc(100vh - 64px - 3rem);
  align-items: stretch;
}
.layout.review-mode .options-panel {
  width: auto;
  flex: 1;
  overflow-y: auto;
}
.layout.review-mode .preview-panel {
  flex: 0 0 400px;
  width: 400px;
  overflow-y: auto;
}
/* Disable sticky in review mode — sticky inside a scrolling flex child causes overlap */
.layout.review-mode .preview-sticky {
  position: static;
}
/* Let the panel's own scroll handle table height — remove inner max-height cap */
.layout.review-mode .vtable-wrap {
  max-height: none;
}

.preview-sticky {
  position: sticky;
  top: 1.5rem;
}

.preview-heading {
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.preview-subtext {
  font-size: 0.8rem;
  font-weight: 400;
  color: #999;
}

.preview-container {
  background: #eceae1;
  border-radius: 10px;
  overflow: hidden;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.10);
}

.preview-loader {
  color: #999;
  font-size: 0.85rem;
  padding: 2rem;
}

.preview-img {
  width: 100%;
  display: block;
  border-radius: 8px;
}

/* Issue navigator (Stage 3 preview panel) */
.issue-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.75rem;
  gap: 0.5rem;
}

.issue-nav button {
  background: #fff;
  border: 1.5px solid #d0d0c8;
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: #444;
  transition: border-color 0.15s;
}

.issue-nav button:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
}

.issue-nav button:disabled {
  opacity: 0.4;
  cursor: default;
}

.issue-counter {
  font-size: 0.8rem;
  color: #666;
  white-space: nowrap;
}

/* Responsive: stack at narrow widths */
@media (max-width: 820px) {
  .layout {
    flex-direction: column-reverse;
  }
  .options-panel {
    width: 100%;
  }
  .preview-sticky {
    position: static;
  }
  .layout.review-mode .options-panel,
  .layout.review-mode .preview-panel {
    flex: none;
    width: 100%;
  }
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  text-align: center;
  margin-bottom: 1.25rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #1a1a1a;
}

.subtitle {
  margin-top: 0.3rem;
  color: #666;
  font-size: 0.9rem;
}

/* ── Wizard nav ─────────────────────────────────────────────────────────── */

.wizard-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.wstep {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #aaa;
  font-weight: 500;
  transition: color 0.2s, background 0.2s;
}

.wstep-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #e0e0d8;
  color: #888;
  font-size: 0.72rem;
  font-weight: 700;
  transition: background 0.2s, color 0.2s;
}

.wstep.active .wstep-num {
  background: var(--blue);
  color: #fff;
}

.wstep.active {
  color: var(--blue);
}

.wstep.done .wstep-num {
  background: #27ae60;
  color: #fff;
}

.wstep.done {
  color: #27ae60;
}

.wstep-arrow {
  color: #ccc;
  font-size: 0.85rem;
  line-height: 1;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.card h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.7rem;
  color: #1a1a1a;
}

.optional {
  font-weight: 400;
  color: #888;
  font-size: 0.82rem;
}

.hint {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.85rem;
}

.hint code {
  background: #f0f0eb;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 0.78rem;
}

/* ── Stage visibility ───────────────────────────────────────────────────── */

.stage {
  /* visible by default; JS adds .hidden to inactive stages */
}

/* ── Stage footer (back / next / generate buttons) ─────────────────────── */

.stage-footer {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.btn-back {
  background: #fff;
  border: 1.5px solid #d0d0c8;
  border-radius: 8px;
  padding: 0.6rem 1.25rem;
  font-size: 0.88rem;
  color: #555;
  cursor: pointer;
  transition: border-color 0.2s;
}

.btn-back:hover {
  border-color: #888;
}

.btn-sample {
  display: block;
  width: 100%;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-sample:hover:not(:disabled) {
  background: var(--blue-h);
}

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

.preview-btns {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.preview-btns .btn-sample,
.preview-btns .btn-next,
.preview-btns .btn-back {
  flex: 1;
  margin-top: 0;
}

.btn-next {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-next:hover:not(:disabled) {
  background: var(--blue-h);
}

.btn-next:disabled {
  background: #80aaf0;
  cursor: not-allowed;
}

.btn-generate {
  background: #27ae60;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-generate:hover:not(:disabled) {
  background: #229954;
}

.btn-generate:disabled {
  background: #90c4a8;
  cursor: not-allowed;
}

/* ── File drop zone ─────────────────────────────────────────────────────── */

.file-drop-zone {
  position: relative;
  border: 2px dashed #d0d0c8;
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-drop-zone:hover {
  border-color: var(--blue);
  background: #f0f4ff;
}

.file-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-drop-zone label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: #555;
  pointer-events: none;
}

.drop-icon {
  font-size: 1.6rem;
}

.sample-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--blue);
  text-decoration: none;
}

.sample-link:hover {
  text-decoration: underline;
}

/* CSV parse feedback */
.csv-status {
  margin-top: 0.6rem;
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
}

.csv-status.ok {
  background: #eafaf1;
  color: #1e8449;
}

.csv-status.error {
  background: #fff0f0;
  color: #c0392b;
}

/* ── Toggle group ───────────────────────────────────────────────────────── */

.profile-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--dark);
  background: var(--white);
  border: 1.5px solid #d0d0c8;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.profile-select:focus {
  outline: none;
  border-color: var(--blue);
}

.toggle-group {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.toggle-option {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  border: 1.5px solid #d0d0c8;
  border-radius: 20px;
  transition: border-color 0.15s, background 0.15s;
}

.toggle-option:has(input:checked) {
  border-color: var(--blue);
  background: #f0f4ff;
}

.toggle-option input {
  accent-color: var(--blue);
}

.toggle-sub {
  font-size: 0.72rem;
  color: #888;
  margin-left: 0.1rem;
}

/* ── Ink color picker ───────────────────────────────────────────────────── */

.ink-color-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

input[type="color"] {
  width: 2.25rem;
  height: 2.25rem;
  border: 1.5px solid #d0d0c8;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
  background: none;
}

.ink-swatches {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.swatch {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.swatch:hover {
  transform: scale(1.15);
}

.swatch.active {
  border-color: #2c2c2c;
}

/* ── Return address ─────────────────────────────────────────────────────── */

.return-section {
  margin-top: 0.5rem;
}

.return-section textarea {
  width: 100%;
  border: 1.5px solid #d0d0c8;
  border-radius: 8px;
  padding: 0.65rem;
  font-size: 0.88rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.return-section textarea:focus {
  border-color: var(--blue);
}

/* ── Submit / status / result ───────────────────────────────────────────── */

.status {
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  text-align: center;
  width: 100%;
  margin-top: 0.5rem;
}

.status.info  { background: #eef2ff; color: var(--blue); }
.status.error { background: #fff0f0; color: #c0392b; }

.result {
  text-align: center;
}

.result h2 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

#result-message {
  color: #555;
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
}

.download-btn {
  display: inline-block;
  background: #27ae60;
  color: #fff;
  text-decoration: none;
  padding: 0.65rem 1.75rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
  transition: background 0.2s;
}

.download-btn:hover {
  background: #229954;
}

.reset-btn {
  display: block;
  margin: 0 auto;
  background: none;
  border: 1.5px solid #d0d0c8;
  border-radius: 8px;
  padding: 0.45rem 1.4rem;
  font-size: 0.85rem;
  color: #555;
  cursor: pointer;
  transition: border-color 0.2s;
}

.reset-btn:hover {
  border-color: #888;
}

/* ── Validation — summary bar ───────────────────────────────────────────── */

.summary-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  background: #f8f8f4;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.summary-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
}

.summary-chip.ok      { color: #1e8449; }
.summary-chip.warning { color: #b7770d; }
.summary-chip.error   { color: #c0392b; }

.summary-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.summary-dot.ok      { background: #27ae60; }
.summary-dot.warning { background: #f0a500; }
.summary-dot.error   { background: #e74c3c; }

/* ── Validation — filter tabs ───────────────────────────────────────────── */

.filter-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.filter-tab {
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  border: 1.5px solid #d0d0c8;
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  color: #555;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.filter-tab.active {
  border-color: var(--blue);
  background: #f0f4ff;
  color: var(--blue);
  font-weight: 600;
}

/* ── Validation — table ─────────────────────────────────────────────────── */

.vtable-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1.5px solid #e8e8e0;
  max-height: 360px;
  overflow-y: auto;
  background: var(--white);
}

.vtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.vtable thead th {
  background: #f5f5f0;
  padding: 0.45rem 0.6rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: #666;
  border-bottom: 1.5px solid #e8e8e0;
  position: sticky;
  top: 0;
  z-index: 1;
}

.vtable tbody tr {
  border-bottom: 1px solid #f0f0e8;
  cursor: pointer;
  transition: background 0.1s;
}

.vtable tbody tr:hover {
  background: #fafaf6;
}

.vtable tbody tr.selected {
  background: #eef3ff;
}

.vtable tbody tr.vrow-error {
  border-left: 3px solid #e74c3c;
}

.vtable tbody tr.vrow-warning {
  border-left: 3px solid #f0a500;
}

.vtable tbody tr.vrow-ok {
  border-left: 3px solid transparent;
}

.vtable td {
  padding: 0.4rem 0.6rem;
  vertical-align: top;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.badge-ok      { background: #eafaf1; color: #1e8449; }
.badge-warning { background: #fef9e7; color: #b7770d; }
.badge-error   { background: #fdf0ef; color: #c0392b; }

/* ── Inline cell editing ────────────────────────────────────────────────── */

.cell-input {
  width: 100%;
  border: 1.5px solid #d0d0c8;
  border-radius: 5px;
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}

.cell-input:focus {
  border-color: var(--blue);
}

.cell-warning .cell-input { border-color: #f0a500; }
.cell-error   .cell-input { border-color: #e74c3c; }

.cell-hint {
  font-size: 0.7rem;
  margin-top: 0.15rem;
}

.cell-hint.hint-warning { color: #b7770d; }
.cell-hint.hint-error   { color: #c0392b; }

/* ── Warnings-override ──────────────────────────────────────────────────── */

.warnings-override {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: #fef9e7;
  border: 1.5px solid #f0d080;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #7d6008;
  cursor: pointer;
}

.warnings-override input[type="checkbox"] {
  accent-color: #b7770d;
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.hidden {
  display: none !important;
}

/* ── Payment section ── */
.payment-section {
  margin-top: 1rem;
  padding: 1rem;
  background: #f0f7ff;
  border: 1.5px solid #bfdbfe;
  border-radius: 10px;
}

.price-display {
  font-size: 0.95rem;
  color: #1e3a5f;
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.price-display strong { font-size: 1.05rem; color: #1d4ed8; }
.price-display s      { color: #999; }
.price-min-warn       { color: #b45309; font-weight: 500; }
.discount-applied     { color: #15803d; font-weight: 600; margin-left: 0.4rem; }

.discount-row {
  display: flex;
  gap: 0.5rem;
}

.discount-row input {
  flex: 1;
  padding: 0.45rem 0.75rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 7px;
  font-size: 0.9rem;
  font-family: inherit;
}

.discount-row input:focus {
  outline: none;
  border-color: #2563eb;
}

.discount-row button {
  padding: 0.45rem 1rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.discount-row button:hover   { background: #1d4ed8; }
.discount-row button:disabled { opacity: 0.6; cursor: default; }

.discount-msg {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.discount-msg.discount-ok  { color: #15803d; }
.discount-msg.discount-err { color: #dc2626; }
