:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --line: #dbe4f0;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #2f6df6;
  --blue-soft: #eaf1ff;
  --green: #0faa72;
  --orange: #f97316;
  --red: #e43f63;
  --shadow: 0 10px 28px rgba(15, 23, 42, .07);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 14px; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.brand-mark { width: 38px; height: 38px; border-radius: 8px; object-fit: contain; flex: 0 0 38px; background: #fff; border: 1px solid var(--line); }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 12px; overflow: auto; padding-right: 2px; }
.nav-label, .nav-parent { color: #70819a; font-weight: 700; font-size: 12px; padding: 4px 8px; }
.nav-parent { width: 100%; text-align: left; background: none; border: 0; display: flex; justify-content: space-between; }
.nav-parent::after { content: "⌄"; color: #94a3b8; }
.nav-children { display: grid; gap: 4px; }
.nav-item { border: 0; background: transparent; color: #334155; text-align: left; padding: 9px 12px; border-radius: var(--radius); font-weight: 600; }
.nav-item:hover { background: #f1f5f9; }
.nav-item.active { background: var(--blue-soft); color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }

.workspace { min-width: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.topbar { height: 54px; flex: 0 0 54px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 0 24px; background: rgba(255, 255, 255, .88); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.status-pills, .top-actions, .head-actions, .inline-actions, .button-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill, .mini-tag, .chip, .state { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.pill.warn { color: #b45309; background: #fff7ed; border: 1px solid #fed7aa; }
.pill.neutral { color: #475569; background: #f1f5f9; border: 1px solid #dbe4f0; }
.pill.safe, .state.on, .chip.ok { color: #047857; background: #ecfdf5; border: 1px solid #bbf7d0; }
.chip.warn, .state.off { color: #be123c; background: #fff1f2; border: 1px solid #fecdd3; }
.ext-input { width: 210px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.avatar { width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--blue); color: white; font-weight: 900; }

.view { display: none; padding: 22px 26px; overflow: hidden; height: calc(100vh - 54px); }
.view.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 18px; }
.page-head.compact { margin-bottom: 14px; }
.crumb { margin: 0 0 8px; color: #718096; font-size: 13px; }
h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: 0; }
h3 { margin: 0 0 14px; font-size: 15px; }
p { color: var(--muted); margin: 8px 0 0; }
.btn { border: 1px solid var(--line); background: #fff; color: #1e293b; border-radius: 8px; padding: 8px 14px; font-weight: 800; }
.btn.primary { background: var(--blue); color: white; border-color: var(--blue); box-shadow: 0 8px 18px rgba(47, 109, 246, .22); }
.btn.ghost { background: #fff; }
.btn.soft { background: var(--blue-soft); color: var(--blue); border-color: #cfe0ff; }
.btn.danger { background: #fff1f2; color: var(--red); border-color: #fecdd3; }
.btn.dark { background: #0f172a; color: white; border-color: #0f172a; }
.btn.brown { background: #b45309; color: white; border-color: #b45309; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.link-btn { border: 0; background: transparent; color: var(--blue); font-weight: 800; }

.guide-row { display: grid; grid-template-columns: 1.35fr 1fr 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.guide-step, .metric, .panel, .table-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.guide-step { min-height: 126px; padding: 18px; }
.guide-step b { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: #10b981; color: #fff; margin-bottom: 12px; }
.badge.muted { display: inline-flex; background: #eef2f7; color: #475569; border-radius: 999px; padding: 4px 8px; font-size: 12px; margin-bottom: 10px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metric-grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.metric-grid.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric { padding: 16px; min-height: 96px; }
.metric span, .metric em, td em { color: #718096; font-style: normal; display: block; }
.metric strong { display: block; font-size: 28px; margin-top: 8px; }
.split-panel, .settings-grid { display: grid; grid-template-columns: 1.45fr .75fr; gap: 14px; }
.panel { padding: 18px; }
.panel-title { display: flex; justify-content: space-between; margin-bottom: 16px; }
.country-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.country-grid div { border: 1px solid var(--line); border-radius: 8px; padding: 16px; background: var(--panel-soft); }
.country-grid strong { display: block; font-size: 24px; margin: 8px 0; }
.status-list { padding: 0; margin: 0; list-style: none; display: grid; gap: 10px; }
.status-list li { display: flex; justify-content: space-between; border-bottom: 1px solid #eef2f7; padding-bottom: 8px; }

.mode-row, .toolbar, .bulkbar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-weight: 800; }
.seg.active { background: var(--blue-soft); color: var(--blue); border-color: #bad1ff; }
.toolbar input, .toolbar select, label input, label select, .token-input input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; min-width: 160px; }
.toolbar input { flex: 1; min-width: 260px; }
.bulkbar { justify-content: flex-end; }
.bulkbar span { margin-right: auto; color: var(--muted); font-weight: 700; }
.table-card { overflow: hidden; }
.table-card.tall { height: calc(100vh - 292px); overflow: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; border-bottom: 1px solid #e8eef7; padding: 14px 12px; vertical-align: middle; }
th { color: #64748b; font-size: 12px; background: #f8fbff; }
.product-cell { display: flex; gap: 12px; align-items: center; min-width: 320px; }
.product-cell span, td span { color: #718096; display: block; margin-top: 3px; }
.thumb { width: 46px; height: 46px; border-radius: 8px; border: 1px solid var(--line); background: linear-gradient(135deg, #fbbf24, #7c3aed); }
.thumb.gold { background: linear-gradient(135deg, #facc15, #f97316); }
.thumb.apparel { background: linear-gradient(135deg, #93c5fd, #f9a8d4); }
.thumb.apparel.dark { background: linear-gradient(135deg, #92400e, #fde68a); }

.calc-grid { display: grid; grid-template-columns: .9fr 1fr; gap: 14px; }
.price-card { display: grid; place-items: center; text-align: center; min-height: 235px; }
.price-card strong { font-size: 34px; color: var(--blue); }
.price-card em { font-size: 17px; font-style: normal; }
label { display: grid; gap: 6px; color: #475569; font-weight: 700; margin-bottom: 12px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.two { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.breakdown ul { padding: 0; margin: 0; list-style: none; }
.breakdown li { display: flex; justify-content: space-between; border-bottom: 1px solid #edf2f7; padding: 12px 0; }

.fulfillment-page { height: 100%; overflow: hidden; }
.form-preview { display: grid; grid-template-columns: 1fr 1.1fr; gap: 14px; height: calc(100vh - 190px); min-height: 560px; }
.preview { display: flex; flex-direction: column; justify-content: space-between; }
.label-preview, .blank-label, .manifest-preview { width: 360px; height: 180px; margin: 28px auto; border: 1px solid #94a3b8; background: #fff; display: grid; place-items: center; text-align: center; }
.label-preview { align-content: center; gap: 6px; }
.label-preview strong { border-top: 2px solid #111827; padding-top: 10px; width: 80%; }
.manifest-preview { width: 220px; height: 170px; }
.pdf-stitch-page { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.pdf-stitch-board { display: grid; grid-template-columns: 1.15fr .85fr; gap: 14px; flex: 1; min-height: 0; }
.pdf-stitch-left, .pdf-stitch-right { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pdf-stitch-left .dropzone { flex: 0 0 auto; min-height: 96px; }
.pdf-stitch-queue { flex: 1; min-height: 0; overflow: auto; margin-top: 10px; align-content: start; }
.pdf-stitch-right .button-row { margin-top: auto; }
.pdf-stitch-status { border-radius: var(--radius); padding: 12px 14px; font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.pdf-stitch-status.is-neutral { background: #f8fafc; border: 1px solid var(--line); color: #475569; }
.pdf-stitch-status.is-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; }
.pdf-stitch-status.is-success { background: #ecfdf5; border: 1px solid #bbf7d0; color: #047857; }
.pdf-stitch-status.is-error { background: #fff1f2; border: 1px solid #fecdd3; color: #be123c; }
.pdf-stitch-summary { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.pdf-stitch-summary li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; font-size: 13px; }
.pdf-stitch-summary b { color: #334155; }
.pdf-stitch-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.dropzone { min-height: 260px; border: 1px dashed #93c5fd; border-radius: var(--radius); background: #eff6ff; color: #2563eb; display: grid; place-items: center; font-weight: 800; text-align: center; padding: 12px; cursor: pointer; }
.dropzone.dragover { background: #dbeafe; border-color: #2563eb; }
.queue-empty { color: var(--muted); font-weight: 600; }
.queue-row { display: grid; gap: 4px; }
.queue { margin: 0; padding-left: 0; color: #334155; list-style: none; display: grid; gap: 8px; }
.queue li { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.queue-actions { display: flex; gap: 6px; }
.queue-actions button { padding: 4px 7px; border-radius: 6px; border: 1px solid var(--line); background: #fff; font-size: 12px; font-weight: 800; }
.pdf-stitch-queue .queue-empty { min-height: 46px; display: grid; place-items: center; border-style: dashed; background: #f8fafc; }
.pdf-stitch-queue .pdf-file-row { display: grid; grid-template-columns: minmax(0, 1fr) 72px 92px 118px; gap: 10px; align-items: center; min-height: 52px; padding: 10px 12px; background: #fff; }
.pdf-file-main { min-width: 0; display: grid; gap: 3px; }
.pdf-file-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #0f172a; }
.pdf-file-main span { color: var(--muted); font-size: 12px; }
.pdf-file-pages, .pdf-file-size { color: #334155; font-size: 12px; font-weight: 800; text-align: right; }
.pdf-file-actions { display: flex; justify-content: flex-end; gap: 4px; }
.pdf-file-actions button { width: 30px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: #334155; font-size: 12px; font-weight: 800; }
.pdf-file-actions button:hover:not(:disabled) { border-color: #bfdbfe; color: #2563eb; background: #eff6ff; }
.pdf-file-actions button:disabled { opacity: .42; cursor: not-allowed; }
.blank-label { padding: 16px; color: #334155; font-weight: 800; }
.manifest-preview span { display: block; margin-top: 8px; }
.choice { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fff; }
.choice.active { background: #eef6ff; border-color: #bfdbfe; }
.token-input { display: flex; gap: 8px; margin-bottom: 12px; }
.token-input input { flex: 1; }
.tokens { display: flex; gap: 8px; flex-wrap: wrap; }
.tokens span { background: #eaf1ff; color: #2563eb; border-radius: 999px; padding: 5px 10px; font-weight: 700; font-size: 12px; }
.rule-panel { margin-top: 14px; }
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
.rules div { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; border-bottom: 1px solid #eef2f7; padding: 18px 0; }
.rules span { color: var(--muted); grid-column: 1; }
.rules input { grid-row: 1 / span 2; grid-column: 2; }
.placeholder-page { height: 100%; display: grid; place-content: center; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.a4-feature-mount { padding: 22px 26px; height: 100%; overflow: auto; }
.a4-catalog-toast { position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 9999; font-size: 13px; }
.a4-wh-status { margin: 0 26px 8px; color: var(--muted); font-weight: 700; }
.a4-wh-status.ok { color: #047857; }
.a4-wh-meta { margin: 0 26px 16px; color: var(--muted); font-size: 13px; }
#view-catalog { padding: 0; overflow: hidden; }
#view-catalog.active { display: flex; flex-direction: column; }
.catalog-state { padding: 24px 16px; text-align: center; color: var(--muted); font-weight: 600; }
.catalog-state--auth { color: #b45309; background: #fffbeb; border-radius: 8px; }
.catalog-state--empty { color: #475569; }
.catalog-state--error { color: #be123c; background: #fff1f2; border-radius: 8px; }
.catalog-ops-hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.batch-layout { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
.batch-log { margin-top: 12px; max-height: 320px; overflow: auto; font-size: 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.batch-warn { color: #dc2626; }
.chip { display: inline-block; font-size: 11px; padding: 2px 6px; border-radius: 4px; }
.chip.ok { background: #dcfce7; color: #166534; }
.chip.warn { background: #fef3c7; color: #92400e; }
.memory-radar { margin-top: 12px; padding: 12px; background: #f8fafc; border-radius: 8px; }
.memory-radar.hidden { display: none; }
.sku-memory-count-badge { margin-top: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.a4-modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 10000;
  display: grid; place-items: center; padding: 20px;
}
.a4-modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; max-width: 420px; width: 100%; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}
.a4-modal label { display: block; margin: 10px 0; font-size: 13px; font-weight: 600; }
.a4-modal input[type="text"] { width: 100%; margin-top: 4px; }
.a4-check { font-weight: normal; display: flex; align-items: center; gap: 8px; }
.a4-sync-status { font-size: 11px; color: var(--muted); max-width: 140px; line-height: 1.3; }
.memory-migrate-preview { width: 100%; font-size: 12px; border-collapse: collapse; margin-top: 8px; }
.memory-migrate-preview th, .memory-migrate-preview td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.memory-migrate-modal { max-width: 560px; max-height: 80vh; overflow: auto; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); }
  .metric-grid, .metric-grid.five, .metric-grid.six { grid-template-columns: repeat(3, 1fr); }
  .guide-row, .split-panel, .settings-grid, .form-preview, .pdf-stitch-board, .calc-grid, .batch-layout, .label-workspace { grid-template-columns: 1fr; }
  .view { overflow: auto; }
}
