:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e4e6eb;
  --border-strong: #d3d7dd;
  --text: #16181d;
  --text-dim: #5b6270;
  --text-faint: #8a91a0;
  --accent: #1f5eff;
  --accent-soft: #eaf0ff;
  --ok: #12805c;
  --ok-soft: #e6f6f0;
  --warn: #a15c00;
  --warn-soft: #fff4e3;
  --danger: #c02626;
  --danger-soft: #fdeceb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 24, 33, 0.04), 0 4px 16px rgba(20, 24, 33, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
#app { min-height: 100vh; display: flex; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand-block { padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.brand-block .logo { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-block .logo-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, #1f5eff, #6b3cff);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700;
}
.brand-block .instance { margin-top: 6px; font-size: 11.5px; color: var(--text-faint); }

nav.nav { padding: 10px 10px 20px; overflow-y: auto; flex: 1; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-faint); padding: 14px 8px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-size: 13.5px;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; opacity: 0.9; font-size: 14px; }
.nav-item .badge {
  margin-left: auto; background: var(--danger-soft); color: var(--danger);
  border-radius: 20px; padding: 0 6px; font-size: 11px; font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 15px; font-weight: 620; margin: 0; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }
.content { padding: 20px; max-width: 1440px; width: 100%; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  padding: 7px 13px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 550; transition: 0.12s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(0.95); }
.btn.danger { color: var(--danger); border-color: #f0c9c6; background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: #fff; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 550; }
label.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }

/* ---------- cards & tables ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-head h2 { font-size: 13.5px; font-weight: 620; margin: 0; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi-grid.three { grid-template-columns: repeat(3, 1fr); }

.nav-toggle { display: none; font-size: 15px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 640; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }
.kpi.ok .value { color: var(--ok); }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); font-weight: 650; padding: 9px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:hover td { background: #fafbfd; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text-dim); white-space: nowrap;
}
.tag.ok { background: var(--ok-soft); border-color: #bfe6d7; color: var(--ok); }
.tag.warn { background: var(--warn-soft); border-color: #f2ddb8; color: var(--warn); }
.tag.danger { background: var(--danger-soft); border-color: #f3c9c6; color: var(--danger); }
.tag.info { background: var(--accent-soft); border-color: #cfdcff; color: var(--accent); }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar input[type=text] { max-width: 320px; }

.empty { padding: 40px 16px; text-align: center; color: var(--text-faint); font-size: 13px; }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-dim); }
.pager .spacer { flex: 1; }

/* ---------- auth / wizard ---------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; width: 100%; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.02em; }
.auth-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.wizard-steps { list-style: none; padding: 0; margin: 0 0 18px; }
.wizard-steps li { display: flex; gap: 9px; align-items: center; font-size: 12.5px; color: var(--text-faint); padding: 3px 0; }
.wizard-steps li.done { color: var(--ok); font-weight: 600; }

.alert-banner {
  padding: 10px 13px; border-radius: var(--radius-sm); font-size: 12.5px;
  margin-bottom: 14px; border: 1px solid;
}
.alert-banner.error { background: var(--danger-soft); border-color: #f3c9c6; color: var(--danger); }
.alert-banner.info { background: var(--accent-soft); border-color: #cfdcff; color: var(--accent); }
.alert-banner.warn { background: var(--warn-soft); border-color: #f2ddb8; color: var(--warn); }
.alert-banner.ok { background: var(--ok-soft); border-color: #bfe6d7; color: var(--ok); }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 20, 28, 0.42); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 720px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(10, 14, 22, 0.3); }
.modal header { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 14.5px; font-weight: 620; }
.modal .modal-body { padding: 18px; overflow-y: auto; }
.modal footer { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 80;
  background: #16181d; color: #fff; padding: 10px 15px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); max-width: 380px;
}
.toast.error { background: #8f1d1d; }
.toast.ok { background: #0f5e46; }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: -240px; z-index: 40; transition: left 0.2s; box-shadow: 0 0 40px rgba(10,14,22,0.25); }
  .sidebar.open { left: 0; }
  .nav-toggle { display: inline-flex; }
  .kpi-grid.three { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- core-first console: dashboard, imports, nav groups ---------- */
.muted { color: var(--text-faint); font-size: 12.5px; }

.nav-group-label.toggle {
  display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap;
  user-select: none; margin-top: 10px; border-top: 1px solid var(--border); padding-top: 12px;
}
.nav-group-label.toggle:hover { color: var(--text-dim); }
.nav-group-label.toggle .chip {
  font-size: 9.5px; letter-spacing: 0; text-transform: none; padding: 1px 6px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-faint);
}
.nav-group-label.toggle .caret { margin-left: auto; font-size: 10px; }

.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.dash-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.02em; }
.dash-head p { margin: 4px 0 0; color: var(--text-dim); font-size: 12.5px; }

.dash-grid { display: grid; grid-template-columns: 1.32fr 1fr; gap: 14px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

.setup-steps { list-style: none; margin: 0; padding: 0; }
.setup-steps li {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.setup-steps li:last-child { border-bottom: 0; }
.setup-steps .dot {
  width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 650;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-dim);
}
.setup-steps li.done .dot { background: var(--ok-soft); border-color: #bfe6d7; color: var(--ok); }
.setup-steps .txt { min-width: 0; flex: 1; }
.setup-steps .txt .t { font-size: 13.5px; font-weight: 600; }
.setup-steps .txt .h { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.setup-steps li.done .txt .t { color: var(--text-dim); }

.src-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 13px;
}
.src-row:last-of-type { border-bottom: 0; }
.src-row > span { color: var(--text-dim); }
.src-row strong { font-weight: 600; text-align: right; }
.src-note { margin-top: 10px; font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; margin-bottom: 10px; }
.seg-btn {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 6px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.seg-btn.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(20,24,33,0.08); }

.import-row { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.file-drop {
  display: inline-flex; align-items: baseline; gap: 8px; cursor: pointer;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 12px; background: var(--surface-2); font-size: 13px; color: var(--accent);
}
.file-drop:hover { border-color: var(--accent); }
.file-drop small { color: var(--text-faint); font-size: 11.5px; }

.csv-input {
  width: 100%; resize: vertical; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
}
.csv-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.import-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.import-actions .grow { flex: 1; }

.import-result { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.import-result.ok { border-color: #bfe6d7; }
.import-result .res-head { padding: 10px 14px; font-weight: 620; font-size: 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.import-result.ok .res-head { background: var(--ok-soft); color: var(--ok); border-bottom-color: #bfe6d7; }
.res-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); }
.res-grid > div { background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.res-grid span { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.res-grid strong { font-size: 18px; font-weight: 640; }
.res-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }
.res-foot .grow { flex: 1; }
.import-result .alert-banner { margin: 0 14px 12px; }

@media (max-width: 700px) {
  .res-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-head { flex-direction: row; align-items: flex-start; gap: 10px; }
  .dash-lead { flex: 1; }
  .scope-box { flex-direction: column; align-items: stretch; }
  .scope-box code { word-break: break-word; }
}

/* ---------- store connection wizard ---------- */
.shop-list { display: grid; gap: 10px; margin-bottom: 16px; }

.shop-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px;
}
.shop-main { min-width: 0; }
.shop-name { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 620; letter-spacing: -0.015em; }
.shop-meta { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.shop-meta.mono { font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.shop-err { font-size: 11.5px; color: var(--danger); margin-top: 5px; }
.shop-acts { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 860px) {
  .shop-card { flex-direction: column; align-items: stretch; }
  .shop-acts { justify-content: flex-start; }
}

.wizard { padding: 0; overflow: hidden; }
.wizard > summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  padding: 14px 17px; font-size: 13.5px; font-weight: 600; color: var(--text);
}
.wizard > summary::-webkit-details-marker { display: none; }
.wizard > summary:hover { background: var(--surface-2); }
.wiz-plus {
  width: 19px; height: 19px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 500; line-height: 1;
}
.wizard > .card-body { border-top: 1px solid var(--border); padding-top: 4px; }

.wiz-steps { list-style: none; margin: 0; padding: 0; }
.wiz-steps > li { display: flex; gap: 13px; padding: 16px 0; border-bottom: 1px dashed var(--border); }
.wiz-steps > li:last-child { border-bottom: 0; }
.wiz-n {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 650;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text-dim);
}
.wiz-c { min-width: 0; flex: 1; }
.wiz-t { font-size: 13.5px; font-weight: 600; margin-bottom: 3px; }
.wiz-b { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }
.wiz-link { display: inline-block; margin-top: 7px; font-size: 12.5px; color: var(--accent); text-decoration: none; }
.wiz-link:hover { text-decoration: underline; }
.wiz-note {
  margin-top: 9px; font-size: 11.5px; color: var(--text-faint); line-height: 1.6;
  padding-left: 10px; border-left: 2px solid var(--border-strong);
}

.scope-box {
  display: flex; align-items: center; gap: 9px; margin-top: 9px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.scope-box code { flex: 1; font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); word-break: break-all; }

.wiz-form { display: grid; grid-template-columns: repeat(2, minmax(0, 330px)); gap: 0 16px; margin-top: 11px; }
.wiz-form .field:last-child { grid-column: 1 / -1; max-width: 320px; }
@media (max-width: 700px) { .wiz-form { grid-template-columns: 1fr; } }
.wiz-form small { display: block; margin-top: 4px; font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }
.wiz-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.wiz-actions .grow { flex: 1; }

.dash-lead { margin: 0; font-size: 13px; color: var(--text-dim); line-height: 1.6; }

.wiz-form input, .wiz-form select { width: 100%; }

/* one-click Shopify authorisation link */
.link-row { display: flex; gap: 8px; margin-top: 14px; }
.link-row input {
  flex: 1; min-width: 0; height: 38px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-size: 11.5px;
  text-overflow: ellipsis;
}
.link-meta { margin-top: 8px; font-size: 11px; color: var(--text-faint); display: flex; gap: 10px; flex-wrap: wrap; }
.link-row input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#ch-link-box[hidden] { display: none; }

details.fallback { margin-top: 18px; border-top: 1px dashed var(--border); }
details.fallback > summary {
  padding: 14px 0 4px; font-size: 12.5px; color: var(--text-dim); cursor: pointer;
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.fallback > summary::-webkit-details-marker { display: none; }
details.fallback > summary::before {
  content: "+"; font-family: var(--mono); font-size: 12px; color: var(--text-faint);
}
details.fallback[open] > summary::before { content: "−"; }
details.fallback > summary:hover { color: var(--text); }

