:root {
  --bg: #f6f7f8; --panel: #ffffff; --ink: #15191e; --ink-2: #4a535e; --ink-3: #6b7480;
  --line: #e2e5e9; --line-2: #eef0f2; --accent: #0b6e69; --accent-ink: #ffffff; --accent-soft: #e3f2f1;
  --warn: #9a5b00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea; --ok: #1a7f37; --ok-soft: #e6f4ea;
  --brand: #4338ca; --brand-soft: #eceafd;
  --radius: 8px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--ink-3); } .mono { font-family: var(--mono); font-size: 12.5px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.logo svg { color: var(--accent); }
.topbar .spacer { flex: 1; }
.brand-switch { display: flex; align-items: center; gap: 8px; }
.brand-switch label { color: var(--ink-3); font-size: 13px; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--ink-2); text-decoration: none; min-height: 36px; }
.nav a:hover { background: var(--line-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 0 7px; }
main { overflow: auto; padding: 20px 24px 40px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: #c9ced4; background: #fafbfb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #095c58; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=number], input[type=url], select, textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .field > .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.field .hint { font-size: 12px; color: var(--ink-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; gap: 8px; align-items: center; min-height: 32px; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.brand { background: var(--brand-soft); color: var(--brand); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* panels & tables */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-body { padding: 14px; }
.table-wrap { overflow: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); background: #fafbfb; position: sticky; top: 0; z-index: 1; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: #f8fafa; }
tbody tr.row[aria-selected="true"] { background: var(--accent-soft); }
td.code { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
td .sub { color: var(--ink-3); font-size: 12.5px; }
.overridden { box-shadow: inset 3px 0 0 var(--brand); }
.inactive td { color: var(--ink-3); }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* catalog layout */
.catalog { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
.tree { padding: 6px; position: sticky; top: 0; }
.tree button { display: flex; width: 100%; text-align: left; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 8px; border-radius: 6px; cursor: pointer; color: var(--ink-2); min-height: 34px; }
.tree button:hover { background: var(--line-2); }
.tree button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree button.child { padding-left: 24px; font-size: 13.5px; }
.tree .n { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 260px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 0 10px; height: 34px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--ink); color: #fff; border-radius: var(--radius); margin-bottom: 10px; flex-wrap: wrap; }
.bulkbar .btn { height: 30px; }
.bulkbar select, .bulkbar input { height: 30px; color: var(--ink); }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 25, .25); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); z-index: 21; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.08); }
.drawer header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer header .t { flex: 1; min-width: 0; }
.drawer .body { padding: 16px 18px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.inherit { font-size: 12px; color: var(--ink-3); }
.inherit button { font-size: 12px; border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }
.field.is-override input, .field.is-override textarea, .field.is-override select { border-color: #b9b4f5; background: #fbfbff; }
.preview-img { width: 100%; max-height: 180px; object-fit: contain; background: #fafbfb; border: 1px solid var(--line); border-radius: 6px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,20,25,.35); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 10px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal.wide { width: min(980px, 100%); }
.modal header { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--panel); }

/* sync */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff; }
.stat .v { font-size: 22px; font-weight: 650; }
.stat .k { font-size: 12px; color: var(--ink-3); }
.diff { font-size: 12.5px; display: grid; grid-template-columns: 150px 1fr; gap: 2px 10px; margin-top: 4px; }
.diff .f { color: var(--ink-3); }
.diff del { color: var(--bad); text-decoration: line-through; } .diff ins { color: var(--ok); text-decoration: none; }
.log { font-family: var(--mono); font-size: 12px; background: #101418; color: #d9dee3; border-radius: 8px; padding: 10px 12px; max-height: 260px; overflow: auto; }
.log .ok { color: #7ee2a8; } .log .warn { color: #ffcf7a; } .log .error { color: #ff9a8f; }
.callout { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }
.callout.info { background: var(--accent-soft); color: var(--accent); }
details summary { cursor: pointer; padding: 8px 0; font-weight: 600; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; height: auto; }
  .nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav a { white-space: nowrap; }
  main { padding: 16px; }
  .catalog { grid-template-columns: 1fr; }
  .tree { position: static; display: flex; overflow-x: auto; gap: 4px; }
  .tree button { width: auto; white-space: nowrap; }
  .tree button.child { padding-left: 8px; }
  .toolbar input[type=search] { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}

/* fixes */
a.btn { text-decoration: none; color: inherit; }
.bulkbar .btn:not(.primary):not(.ghost) { color: var(--ink); }
.grid2 > * { min-width: 0; }
.drawer input:not([type=checkbox]), .drawer textarea, .drawer select, .modal input:not([type=checkbox]):not([type=radio]), .modal select, .modal textarea { width: 100%; }
td .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 260px; }
@media (max-width: 900px) { .hide-sm { display: none; } }
.inherit { word-break: break-all; }

/* Supplier pricebooks: live readback alongside local drafts. */
.eyebrow { font-size:11px; font-weight:700; letter-spacing:.12em; color:var(--accent); margin-bottom:6px; }
.brand-cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(240px,1fr)); gap:16px; }
.brand-card { padding:24px; text-align:left; cursor:pointer; color:var(--ink); }
.brand-card h2 { margin:0 0 10px; }
.brand-card:hover { border-color:var(--accent); }
.mirror-scope { display:flex; justify-content:space-between; gap:16px; color:var(--ink-3); font-size:12px; margin-bottom:16px; }
.mirror-stats { margin-bottom:20px; }
.mirror-tabs { display:flex; flex-wrap:wrap; gap:8px; margin:20px 0 16px; }
.mirror-thumb { width:42px; height:42px; object-fit:contain; background:#fff; border:1px solid var(--line); border-radius:6px; }
.mirror-detail-image { display:block; max-width:150px; height:120px; object-fit:contain; margin:10px 0 20px; }
.comparison th { min-width:110px; }
.comparison td { min-width:160px; vertical-align:top; }
.comparison pre,.mirror-json { margin:0; white-space:pre-wrap; overflow-wrap:anywhere; font:12px/1.6 var(--mono); max-height:260px; overflow:auto; }
.modal:has(.comparison) { width:min(1100px,95vw); }
@media(max-width:900px) { .mirror-scope { flex-direction:column; gap:4px; } }
