:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --panel-2: #faf8f4;
  --ink: #1f2a24;
  --ink-2: #4b5650;
  --muted: #7d867f;
  --line: #e4ded4;
  --line-2: #efeae2;
  --brand: #375e4c;
  --brand-2: #2b4b3d;
  --brand-soft: #e3ece6;
  --accent: #c0693f;
  --accent-soft: #f6e4d9;
  --ok: #3d7a52;
  --ok-soft: #e1efe5;
  --warn: #b7791f;
  --warn-soft: #f8edd6;
  --bad: #b5463a;
  --bad-soft: #f6e0dc;
  --info: #3b6b8f;
  --info-soft: #e0ebf3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 42, 36, .06), 0 4px 16px rgba(31, 42, 36, .05);
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a17; --panel: #1d2420; --panel-2: #222a25; --ink: #e9ece8; --ink-2: #c3cbc5; --muted: #8d978f;
    --line: #313a34; --line-2: #2a322d; --brand: #7fb49a; --brand-2: #9ccab3; --brand-soft: #24362d;
    --accent: #e08e64; --accent-soft: #3b2a21; --ok: #7cc495; --ok-soft: #1f3327; --warn: #e2b05a; --warn-soft: #3a3020;
    --bad: #e58a7e; --bad-soft: #3d2522; --info: #8db8d8; --info-soft: #1f2e3a; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a17; --panel: #1d2420; --panel-2: #222a25; --ink: #e9ece8; --ink-2: #c3cbc5; --muted: #8d978f;
  --line: #313a34; --line-2: #2a322d; --brand: #7fb49a; --brand-2: #9ccab3; --brand-soft: #24362d;
  --accent: #e08e64; --accent-soft: #3b2a21; --ok: #7cc495; --ok-soft: #1f3327; --warn: #e2b05a; --warn-soft: #3a3020;
  --bad: #e58a7e; --bad-soft: #3d2522; --info: #8db8d8; --info-soft: #1f2e3a; --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-family: var(--serif); font-size: 26px; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 14px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--brand-2); color: #e9f0eb; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
:root[data-theme="dark"] .side { background: #101511; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .side { background: #101511; } }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: #f6efe4; display: grid; place-items: center; flex: none; }
.brand-name { font-family: var(--serif); font-size: 19px; line-height: 1.1; }
.brand-sub { font-size: 11px; opacity: .7; letter-spacing: .04em; text-transform: uppercase; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #dfe9e3; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.nav svg { width: 18px; height: 18px; opacity: .85; flex: none; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; padding: 14px 10px 4px; }
.side-foot { margin-top: auto; font-size: 12px; padding: 10px; border-top: 1px solid rgba(255,255,255,.12); display: flex; flex-direction: column; gap: 6px; }
.side-foot button { background: none; border: 0; color: #dfe9e3; padding: 0; cursor: pointer; text-align: left; font: inherit; opacity: .8; }
.side-foot button:hover { opacity: 1; text-decoration: underline; }
.shell > div { min-width: 0; }
.main { min-width: 0; padding: 26px 32px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.mobile-bar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--brand-2); color: #fff; position: sticky; top: 0; z-index: 40; }
  .mobile-bar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 18px 16px 60px; }
}

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: 500 13.5px var(--sans); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0f1612; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0f1612; } }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 0; }
.icon-btn:hover { color: var(--ink); background: var(--line-2); }

input, select, textarea { font: 14px var(--sans); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); padding: 0; }
select.inline, input.inline { width: auto; height: 34px; padding: 4px 10px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.req { color: var(--accent); margin-left: 3px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.search { position: relative; }
.search input { padding-left: 32px; min-width: 260px; height: 34px; }
.search svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.input-unit { display: flex; align-items: center; }
.input-unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-unit .unit { border: 1px solid var(--line); border-left: 0; padding: 7px 10px; border-radius: 0 8px 8px 0; background: var(--panel-2); color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 12.5px; user-select: none; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-2); }
:root[data-theme="dark"] .chip.on { color: var(--brand); }

/* ---------- cards / tables ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.card-b { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g2, .g3, .g5 { grid-template-columns: 1fr; } }
.kpi { padding: 16px 18px; }
.kpi .v { font-family: var(--serif); font-size: 30px; line-height: 1.1; margin-top: 4px; }
.kpi .l { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; position: sticky; top: 0; }
.t th.sortable { cursor: pointer; }
.t th.sortable:hover { color: var(--ink); }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--panel-2); }
.t tr.sel td { background: var(--brand-soft); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; }
.t td.edit { padding: 3px 6px; min-width: 120px; }
.t td.edit input, .t td.edit select { height: 30px; padding: 4px 8px; border-color: transparent; background: transparent; }
.t td.edit input:hover, .t td.edit select:hover { border-color: var(--line); }
.t td.edit input:focus, .t td.edit select:focus { background: var(--panel); border-color: var(--brand); }
.t td.edit.missing input, .t td.edit.missing select { background: var(--accent-soft); }
.thumb { width: 40px; height: 40px; border-radius: 7px; object-fit: cover; background: var(--line-2); display: block; flex: none; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); }
.thumb.ph svg { width: 18px; height: 18px; }
.prod-cell { display: flex; gap: 10px; align-items: center; min-width: 220px; }
.prod-cell b { font-weight: 600; display: block; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- pills / bars ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-draft { background: var(--line-2); color: var(--ink-2); }
.st-review { background: var(--warn-soft); color: var(--warn); }
.st-approved { background: var(--info-soft); color: var(--info); }
.st-published { background: var(--ok-soft); color: var(--ok); }
.st-archived { background: var(--line-2); color: var(--muted); text-decoration: line-through; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--accent-soft); color: var(--accent); }
.bar { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.bar .track { flex: 1; height: 6px; background: var(--line-2); border-radius: 9px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 9px; background: var(--accent); }
.bar .fill.mid { background: var(--warn); }
.bar .fill.full { background: var(--ok); }
.bar .pct { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2); width: 34px; text-align: right; }
.pipeline { display: flex; height: 12px; border-radius: 9px; overflow: hidden; background: var(--line-2); }
.pipeline > div { height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: 500 14px var(--sans); color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { background: var(--line-2); border-radius: 99px; padding: 0 7px; font-size: 11.5px; margin-left: 6px; }

/* ---------- product editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } }
.ed-head { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.ed-head .hero { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; background: var(--line-2); }
.ed-head .title { flex: 1; min-width: 240px; }
.ed-head .title input.name { font: 600 22px var(--serif); border-color: transparent; padding: 2px 6px; margin-left: -7px; background: transparent; }
.ed-head .title input.name:hover { border-color: var(--line); }
.ed-head .title input.name:focus { background: var(--panel); }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.attr-group { margin-bottom: 16px; }
.attr-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.attr-grid .wide { grid-column: 1 / -1; }
@media (max-width: 700px) { .attr-grid { grid-template-columns: 1fr; } }
.attr-grid .field.missing input, .attr-grid .field.missing select, .attr-grid .field.missing textarea { border-color: var(--accent); background: var(--accent-soft); }
.attr-grid .field.dirty > span::after { content: '•'; color: var(--accent); margin-left: 6px; }
.inherit { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.sticky-save { position: sticky; bottom: 16px; z-index: 5; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 10px 14px; margin-top: 10px; background: var(--ink); color: var(--bg); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.sticky-save .btn { border-color: transparent; }
.ready-item { padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.ready-item:last-child { border-bottom: 0; }
.ready-item .missing-list { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.ready-item .missing-list li { display: inline-block; margin: 2px 4px 2px 0; }
.ready-item .missing-list a { background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 99px; }

/* ---------- assets ---------- */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; background: var(--panel-2); }
.drop:hover, .drop.over { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.asset { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.asset .img { aspect-ratio: 1; background: var(--line-2) center / cover no-repeat; position: relative; }
.asset .img .badge { position: absolute; top: 8px; left: 8px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .04em; }
.asset .meta { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.asset .meta input, .asset .meta select { height: 28px; padding: 3px 8px; font-size: 12.5px; }
.asset.pick { cursor: pointer; }
.asset.pick:hover { border-color: var(--brand); }
.asset.pick.on { outline: 3px solid var(--brand); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 26, 22, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; }
.modal-b { padding: 18px 20px; overflow: auto; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; animation: up .2s ease; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, var(--brand-soft), var(--bg) 60%); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth h1 { margin: 14px 0 4px; }

/* ---------- bulk bar ---------- */
.bulk { display: flex; gap: 10px; align-items: center; padding: 10px 14px; background: var(--brand-soft); border: 1px solid var(--brand); border-radius: var(--radius); margin-bottom: 12px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line-2); font-size: 13px; color: var(--muted); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: 9px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; display: flex; gap: 10px; }
.activity li:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; }
.token { display: inline-block; font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--line-2); border-radius: 5px; padding: 1px 6px; margin: 2px; cursor: pointer; }
.token:hover { background: var(--brand-soft); color: var(--brand); }
.preview-table td { font-size: 12.5px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note { background: var(--info-soft); color: var(--ink-2); border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.note.warn { background: var(--warn-soft); }

.t td.edit .input-unit .unit { display: none; }
.t td.edit .input-unit input { border-radius: 8px; }
