:root {
  --bg: #f7f4ef;
  --surface: #fffdfa;
  --surface-2: #f1ece4;
  --ink: #26221d;
  --ink-2: #5d554b;
  --ink-3: #8c8377;
  --line: #e4ddd2;
  --gold: #a8864f;
  --gold-ink: #7a5f33;
  --gold-soft: #f3eadb;
  --ok: #3f7a52;
  --ok-soft: #e4f0e7;
  --warn: #9a6a12;
  --warn-soft: #f8edd5;
  --bad: #a3402f;
  --bad-soft: #f7e3de;
  --info: #3b5f86;
  --info-soft: #e3ebf4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 15, .05), 0 8px 24px rgba(40, 30, 15, .06);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171512; --surface: #201d19; --surface-2: #2a2621; --ink: #f1ebe2; --ink-2: #c7bdb0; --ink-3: #8f867a;
    --line: #3a342d; --gold: #c9a86e; --gold-ink: #e0c48f; --gold-soft: #3a3024;
    --ok: #7cc293; --ok-soft: #22342a; --warn: #e2b660; --warn-soft: #3a2f1c; --bad: #e88b78; --bad-soft: #3c2420;
    --info: #8db3dc; --info-soft: #1f2b39; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #171512; --surface: #201d19; --surface-2: #2a2621; --ink: #f1ebe2; --ink-2: #c7bdb0; --ink-3: #8f867a;
  --line: #3a342d; --gold: #c9a86e; --gold-ink: #e0c48f; --gold-soft: #3a3024;
  --ok: #7cc293; --ok-soft: #22342a; --warn: #e2b660; --warn-soft: #3a2f1c; --bad: #e88b78; --bad-soft: #3c2420;
  --info: #8db3dc; --info-soft: #1f2b39;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1240px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand b { font: 600 24px/1 var(--serif); letter-spacing: .14em; }
.brand span { color: var(--ink-3); font-size: 13px; letter-spacing: .04em; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { text-decoration: none; padding: 7px 12px; border-radius: 999px; color: var(--ink-2); font-weight: 500; font-size: 14px; white-space: nowrap; }
nav a:hover { background: var(--surface-2); }
nav a.on { background: var(--ink); color: var(--bg); }
nav .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--gold); color: #fff; font-size: 12px; text-align: center; }
.worker-chip { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); }
main { max-width: 1240px; margin: 0 auto; padding: 32px 24px 80px; }
h1 { font: 600 40px/1.1 var(--serif); margin: 0 0 6px; letter-spacing: .01em; }
h2 { font: 600 26px/1.2 var(--serif); margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 10px; font-weight: 600; }
.lede { color: var(--ink-2); margin: 0 0 28px; max-width: 680px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary:hover { opacity: .9; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); outline: none; }
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
textarea.input { resize: vertical; min-height: 84px; }
label.field { display: block; font-weight: 500; font-size: 14px; margin-bottom: 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 22px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.queued, .pill.rendering { background: var(--info-soft); color: var(--info); }
.pill.pending_approval { background: var(--gold-soft); color: var(--gold-ink); }
.pill.live { background: var(--ok-soft); color: var(--ok); }
.pill.failed, .pill.rejected { background: var(--bad-soft); color: var(--bad); }
.pill.publishing { background: var(--warn-soft); color: var(--warn); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }

.banner { padding: 14px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner b { font-weight: 600; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 400px; padding: 36px; text-align: center; }
.login h1 { font-size: 34px; letter-spacing: .16em; }
.login form { display: grid; gap: 12px; margin-top: 22px; }

/* ---------- new job ---------- */
.new-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 28px; align-items: start; }
.sku-row { display: flex; gap: 10px; }
.found { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: center; margin-top: 16px; padding: 14px; border-radius: 12px; background: var(--surface-2); }
.found img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: #fff; }
.found .t { font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 10px; gap: 4px; margin-top: 14px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.styles { display: grid; gap: 12px; }
.style-card { color: var(--ink); display: grid; grid-template-columns: 74px 1fr; gap: 16px; align-items: center; text-align: left; width: 100%; padding: 12px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; }
.style-card:hover { border-color: var(--ink-3); }
.style-card.on { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.swatch { width: 74px; height: 74px; border-radius: 10px; border: 1px solid rgba(0,0,0,.06); position: relative; overflow: hidden; }
.swatch.linen::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(120,90,60,.07) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(120,90,60,.06) 0 1px, transparent 1px 3px); }
.swatch i { position: absolute; left: 50%; top: 46%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 4px solid #d1b06b; border-radius: 50%; }
.swatch i::after { content: ''; position: absolute; left: 50%; bottom: -16px; width: 26px; height: 6px; margin-left: -13px; border-radius: 50%; background: rgba(70,60,52,.18); filter: blur(2px); }
.style-card b { display: block; font-weight: 600; margin-bottom: 2px; }
.style-card span { color: var(--ink-3); font-size: 13.5px; }
.how { display: grid; gap: 14px; counter-reset: s; }
.how li { list-style: none; display: grid; grid-template-columns: 28px 1fr; gap: 12px; color: var(--ink-2); font-size: 14px; }
.how li::before { counter-increment: s; content: counter(s); width: 28px; height: 28px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-ink); display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.how { padding: 0; margin: 0; }

/* ---------- lists ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.job { text-decoration: none; display: block; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease; }
.job:hover { transform: translateY(-2px); }
.job .thumbs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); gap: 2px; }
.job .thumbs img, .job .thumbs .ph { aspect-ratio: 1; width: 100%; object-fit: cover; background: #fff; }
.job .thumbs .ph { display: grid; place-items: center; color: var(--ink-3); font-size: 13px; background: var(--surface-2); }
.job .meta { padding: 14px 16px 16px; }
.job .sku { font-weight: 600; }
.job .title { color: var(--ink-2); font-size: 13.5px; margin: 2px 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.empty { padding: 60px 20px; text-align: center; color: var(--ink-3); border: 1.5px dashed var(--line); border-radius: var(--radius); }
.empty b { display: block; color: var(--ink); font: 600 24px var(--serif); margin-bottom: 6px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr[data-href] { cursor: pointer; }
.tbl tr[data-href]:hover td { background: var(--surface-2); }
.tbl img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; background: #fff; }
.scroll-x { overflow-x: auto; }

/* ---------- job detail ---------- */
.job-head { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: start; margin-bottom: 24px; }
.job-head .facts { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--ink-2); font-size: 14px; margin-top: 8px; }
.job-head .facts a { color: var(--gold-ink); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.versions { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.variant { margin-bottom: 34px; }
.variant-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.variant-h b { font: 600 22px var(--serif); }
.pairs { display: grid; gap: 18px; }
.pair { padding: 14px; }
.pair-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.pair-h .slot { font-weight: 600; text-transform: capitalize; }
.qa { display: flex; gap: 6px; flex-wrap: wrap; }
.side { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.side figure { margin: 0; }
.side figcaption { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 0 0 6px; font-weight: 600; }
.side img, .cmp { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 10px; border: 1px solid var(--line); }
.cmp { position: relative; overflow: hidden; user-select: none; touch-action: none; cursor: ew-resize; }
.cmp img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cmp .after-wrap { position: absolute; inset: 0; clip-path: inset(0 0 0 50%); }
.cmp .handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.cmp .handle::after { content: '⟷'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 36px; height: 36px; border-radius: 50%; background: #fff; color: #333; display: grid; place-items: center; font-size: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.cmp .lbl { position: absolute; top: 10px; padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; }
.cmp .lbl.l { left: 10px; } .cmp .lbl.r { right: 10px; }
.view-toggle { margin-left: auto; }
.panel { position: sticky; top: 84px; display: grid; gap: 18px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; font-size: 13.5px; }
.timeline li { display: grid; grid-template-columns: 10px 1fr; gap: 12px; }
.timeline li::before { content: ''; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--line); }
.timeline li.comment::before { background: var(--gold); }
.timeline li.failed::before, .timeline li.publish_failed::before { background: var(--bad); }
.timeline li.published::before, .timeline li.approved::before { background: var(--ok); }
.timeline .note { color: var(--ink-2); }
.timeline .q { background: var(--gold-soft); color: var(--ink); padding: 8px 10px; border-radius: 8px; margin-top: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; color: var(--ink-2); }
.chips button:hover { border-color: var(--gold); color: var(--ink); }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s ease; max-width: calc(100vw - 32px); z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { padding: 80px 0; text-align: center; color: var(--ink-3); }

@media (max-width: 900px) {
  .new-grid, .layout { grid-template-columns: 1fr; }
  .panel { position: static; }
  .job-head { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; }
}
@media (max-width: 640px) {
  .top-in { padding: 12px 16px; gap: 14px; flex-wrap: wrap; }
  .brand span, .worker-chip { display: none; }
  nav { order: 3; flex-basis: 100%; }
  main { padding: 22px 16px 60px; }
  h1 { font-size: 32px; }
  .side { grid-template-columns: 1fr; }
  .sku-row { flex-direction: column; }
}
