:root {
  --bg: #faf9f8;
  --surface: #ffffff;
  --text: #323130;
  --text-2: #605e5c;
  --text-3: #8a8886;
  --border: #edebe9;
  --border-2: #c8c6c4;
  --primary: #0078d4;
  --primary-hover: #106ebe;
  --primary-soft: #eff6fc;
  --primary-soft-2: #deecf9;
  --header: #1b1a19;
  --header-text: #ffffff;
  --danger: #a4262c;
  --success: #107c10;
  --warn: #d83b01;
  --row-hover: #f3f2f1;
  --shadow: 0 6.4px 14.4px rgba(0,0,0,.13), 0 1.2px 3.6px rgba(0,0,0,.11);
  --font: "Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  height: 40px;
  flex: 0 0 40px;
  background: var(--header);
  color: var(--header-text);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
}
.waffle {
  width: 48px; height: 40px; border: 0; background: transparent; color: #fff;
  display: grid; place-items: center;
}
.waffle:hover, .top-icons button:hover { background: rgba(255,255,255,.1); }
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.global-search {
  flex: 1; max-width: 520px; margin: 0 auto; position: relative;
  display: flex; align-items: center; gap: 8px;
  background: #fff; color: var(--text-2); border-radius: 2px; padding: 0 10px; height: 28px;
}
.global-search input { border: 0; outline: 0; flex: 1; height: 100%; background: transparent; min-width: 0; }
.global-results {
  position: absolute; top: 32px; left: 0; right: 0; background: #fff; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto; z-index: 50; border-radius: 2px;
}
.global-results .gr-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.global-results .gr-item:hover, .global-results .gr-item.active { background: var(--row-hover); }
.gr-item .gr-name { color: var(--text); font-weight: 600; }
.gr-item .gr-path { color: var(--text-2); font-size: 12px; }
.gr-empty { padding: 12px; color: var(--text-2); }
.top-icons { display: flex; align-items: center; gap: 2px; }
.top-icons button {
  position: relative; width: 40px; height: 40px; border: 0; background: transparent; color: #fff;
  display: grid; place-items: center;
}
.badge {
  position: absolute; top: 6px; right: 6px; background: var(--primary); color: #fff; font-size: 10px;
  min-width: 14px; height: 14px; border-radius: 7px; display: grid; place-items: center; padding: 0 3px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: #8764b8; color: #fff; font-size: 11px;
  display: grid; place-items: center; font-weight: 600; margin-left: 6px;
}

/* ---------- Platform bar ---------- */
.platformbar {
  flex: 0 0 auto;
  display: flex; align-items: stretch; gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  overflow-x: auto;
}
.platformbar button {
  border: 0; background: transparent; padding: 0 16px; height: 44px; position: relative;
  display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--text);
}
.platformbar button:hover { background: var(--row-hover); }
.platformbar button.active { font-weight: 600; }
.platformbar button.active::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 2px; background: var(--primary);
}
.platformbar .pf-icon { width: 16px; height: 16px; display: inline-grid; place-items: center; color: var(--primary); }
.platformbar .pf-label { font-size: 12px; color: var(--text-2); margin-right: 8px; display: flex; align-items: center; }

/* ---------- Shell ---------- */
.shell { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 280px; flex: 0 0 280px; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px 0 24px;
}
.side-search { margin: 0 12px 10px; position: relative; }
.side-search input {
  width: 100%; height: 30px; border: 1px solid var(--border-2); border-radius: 2px; padding: 0 8px 0 28px;
}
.side-search svg { position: absolute; left: 8px; top: 8px; color: var(--text-2); }
.side-head {
  font-size: 12px; font-weight: 600; color: var(--text-2); padding: 12px 16px 4px; text-transform: none;
}
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 7px 16px; color: var(--text); position: relative; line-height: 1.3;
}
.side-item:hover { background: var(--row-hover); }
.side-item.active { background: var(--primary-soft-2); font-weight: 600; }
.side-item.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.side-item .si-icon { width: 16px; flex: 0 0 16px; color: var(--primary); display: grid; place-items: center; }
.side-item .si-count { margin-left: auto; font-size: 11px; color: var(--text-3); font-weight: 400; }
.side-sub { font-size: 11px; color: var(--text-3); padding: 8px 16px 2px; text-transform: uppercase; letter-spacing: .04em; }

.main { flex: 1; min-width: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* ---------- Page header ---------- */
.crumbs { font-size: 13px; color: var(--text-2); padding: 14px 24px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--primary); }
.crumbs .sep { color: var(--text-3); }
.page-head { padding: 6px 24px 12px; display: flex; align-items: flex-start; gap: 12px; }
.page-head .ph-icon {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 4px; background: var(--primary-soft-2); color: var(--primary);
  display: grid; place-items: center;
}
.page-head h1 { font-size: 20px; font-weight: 600; margin: 0; line-height: 1.3; }
.page-head .ph-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.page-head .ph-actions { margin-left: auto; display: flex; gap: 8px; }

.toolbar {
  display: flex; align-items: center; gap: 4px; padding: 4px 20px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tb-btn {
  border: 0; background: transparent; padding: 6px 8px; display: inline-flex; align-items: center; gap: 6px; border-radius: 2px;
}
.tb-btn:hover { background: var(--row-hover); }
.tb-btn svg { color: var(--primary); }
.tb-btn:disabled { color: var(--text-3); cursor: default; background: transparent; }
.tb-btn:disabled svg { color: var(--text-3); }

/* ---------- Wizard ---------- */
.steps {
  display: flex; gap: 0; padding: 0 24px; border-bottom: 1px solid var(--border); overflow-x: auto; background: var(--surface);
}
.step {
  border: 0; background: transparent; padding: 12px 18px 12px 0; display: flex; align-items: center; gap: 8px;
  white-space: nowrap; color: var(--text-2); position: relative;
}
.step .num {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--text-3); display: grid; place-items: center;
  font-size: 12px; color: var(--text-2); background: var(--surface);
}
.step.done .num { background: var(--success); border-color: var(--success); color: #fff; }
.step.current { color: var(--text); font-weight: 600; }
.step.current .num { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.current::after { content: ""; position: absolute; left: 0; right: 18px; bottom: 0; height: 2px; background: var(--primary); }

.content { padding: 20px 24px 24px; flex: 1; }
.content.narrow { max-width: 900px; }
.wiz-footer {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px 24px; display: flex; gap: 8px; align-items: center; z-index: 5;
}
.wiz-footer .spacer { flex: 1; }
.btn {
  height: 32px; padding: 0 16px; border-radius: 2px; border: 1px solid var(--border-2); background: var(--surface);
  font-weight: 600; min-width: 80px;
}
.btn:hover { background: var(--row-hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Form fields ---------- */
.field { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 8px 16px; margin-bottom: 16px; align-items: start; max-width: 860px; }
.field > label { padding-top: 6px; font-weight: 600; }
.field > label .req { color: var(--danger); margin-left: 2px; }
.field .ro { padding-top: 6px; color: var(--text); }
.field .help { color: var(--text-2); font-size: 12px; margin-top: 4px; }
.tb, .sel, .ta {
  width: 100%; border: 1px solid var(--border-2); border-radius: 2px; background: var(--surface); padding: 0 8px; height: 32px;
}
.ta { height: auto; min-height: 72px; padding: 6px 8px; resize: vertical; }
.tb:hover, .sel:hover, .ta:hover { border-color: var(--text); }
.tb:focus, .sel:focus, .ta:focus { outline: 0; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.tb.invalid { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.num-wrap { display: flex; align-items: center; gap: 8px; }
.num-wrap .tb { max-width: 160px; }
.num-wrap .unit { color: var(--text-2); font-size: 12px; }

.section-title { font-size: 16px; font-weight: 600; margin: 4px 0 12px; }
.section-desc { color: var(--text-2); margin: -6px 0 16px; max-width: 860px; line-height: 1.45; }

/* ---------- Settings ---------- */
.cfg-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.search-box { position: relative; flex: 0 1 360px; }
.search-box input { width: 100%; height: 32px; border: 1px solid var(--border-2); border-radius: 2px; padding: 0 8px 0 30px; }
.search-box svg { position: absolute; left: 9px; top: 9px; color: var(--text-2); }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text); user-select: none; cursor: pointer; }
.chk input { accent-color: var(--primary); width: 15px; height: 15px; margin: 0; }
.cfg-meta { color: var(--text-2); font-size: 12px; margin-left: auto; }
.link-btn { border: 0; background: transparent; color: var(--primary); padding: 0; }
.link-btn:hover { text-decoration: underline; }

.cat { border: 1px solid var(--border); background: var(--surface); margin-bottom: 8px; border-radius: 2px; }
.cat-head {
  width: 100%; border: 0; background: transparent; display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  text-align: left; font-weight: 600; font-size: 14px;
}
.cat-head:hover { background: var(--row-hover); }
.cat-head .chev { transition: transform .15s; color: var(--text-2); flex: 0 0 auto; }
.cat.open .cat-head .chev { transform: rotate(90deg); }
.cat-head .cat-count { margin-left: auto; font-weight: 400; color: var(--text-2); font-size: 12px; white-space: nowrap; }
.cat-head .cat-count b { color: var(--primary); font-weight: 600; }
.cat-body { display: none; border-top: 1px solid var(--border); }
.cat.open .cat-body { display: block; }
.cat-desc { padding: 10px 16px 0; color: var(--text-2); font-size: 13px; line-height: 1.45; }

.setting {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 380px); gap: 8px 24px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); align-items: start;
}
.setting:last-child { border-bottom: 0; }
.setting.sub { padding-left: 40px; background: #fcfcfb; }
.setting.sub.d2 { padding-left: 64px; }
.setting.configured .s-name::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  margin-right: 8px; vertical-align: middle; position: relative; top: -1px;
}
.setting.hit { background: #fffbe6; }
.s-name { font-weight: 400; line-height: 1.4; }
.info {
  display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--text-2);
  color: var(--text-2); font-size: 10px; font-weight: 600; margin-left: 6px; cursor: help; vertical-align: middle;
  font-family: Georgia, serif; font-style: italic; line-height: 1;
}
.info:hover, .info:focus { border-color: var(--primary); color: var(--primary); outline: 0; }
.s-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.45; margin-top: 4px; }
.s-ctl { min-width: 0; }
.s-remove { border: 0; background: transparent; color: var(--text-2); padding: 2px 4px; margin-left: 6px; border-radius: 2px; }
.s-remove:hover { background: var(--row-hover); color: var(--danger); }

.seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 2px; overflow: hidden; max-width: 100%; flex-wrap: wrap; }
.seg button {
  border: 0; background: var(--surface); padding: 5px 12px; min-height: 30px; border-right: 1px solid var(--border-2); white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--row-hover); }
.seg button.on { background: var(--primary); color: #fff; }

.list-ed { display: flex; flex-direction: column; gap: 6px; }
.list-ed .add-row { display: flex; gap: 6px; }
.list-ed .add-row .tb { flex: 1; }
.list-ed .item {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--bg); padding: 3px 4px 3px 8px;
  border-radius: 2px; font-size: 13px; word-break: break-all;
}
.list-ed .item span { flex: 1; }
.mini-btn { border: 1px solid var(--border-2); background: var(--surface); border-radius: 2px; padding: 0 10px; height: 32px; white-space: nowrap; }
.mini-btn:hover { background: var(--row-hover); }
.x-btn { border: 0; background: transparent; width: 24px; height: 24px; border-radius: 2px; color: var(--text-2); display: grid; place-items: center; }
.x-btn:hover { background: var(--border); color: var(--danger); }

.tbl-ed { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl-ed th { text-align: left; font-weight: 600; color: var(--text-2); padding: 4px 6px; border-bottom: 1px solid var(--border-2); white-space: nowrap; }
.tbl-ed td { padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; word-break: break-word; }
.tbl-ed td .tb { height: 28px; }
.tbl-wrap { overflow-x: auto; }
.setting.wide { grid-template-columns: minmax(0, 1fr); }

.multi { display: flex; flex-direction: column; gap: 6px; }
.file-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-ctl .fname { color: var(--text-2); font-size: 13px; word-break: break-all; }
.file-ctl input[type=file] { display: none; }

.empty {
  text-align: center; color: var(--text-2); padding: 48px 16px; border: 1px dashed var(--border-2); border-radius: 2px; background: var(--surface);
}
.empty h3 { color: var(--text); margin: 8px 0 4px; font-size: 16px; }

/* ---------- Tables ---------- */
.grid-tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.grid-tbl th {
  text-align: left; font-weight: 600; font-size: 13px; padding: 9px 12px; border-bottom: 1px solid var(--border-2); white-space: nowrap; color: var(--text);
}
.grid-tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.grid-tbl tbody tr:hover { background: var(--row-hover); }
.grid-tbl .muted { color: var(--text-2); }
.grid-tbl td .sel { height: 28px; }
.tbl-scroll { overflow-x: auto; border: 1px solid var(--border); }
.pill {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--row-hover); color: var(--text); margin: 1px 2px 1px 0;
}
.pill.yes { background: #dff6dd; color: #0b5a08; }
.pill.no { background: #f3f2f1; color: var(--text-2); }

.assign-block { margin-bottom: 28px; max-width: 980px; }
.assign-block h3 { font-size: 15px; margin: 0 0 4px; }
.assign-links { display: flex; gap: 18px; margin: 6px 0 10px; flex-wrap: wrap; }
.assign-links a { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Review ---------- */
.review-sec { margin-bottom: 26px; max-width: 980px; }
.review-sec h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 12px; }
.review-sec h2 a { font-size: 13px; font-weight: 400; }
.kv { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 6px 16px; font-size: 13px; }
.kv .k { color: var(--text-2); }
.kv .v { word-break: break-word; }
.review-cat { font-weight: 600; margin: 14px 0 6px; font-size: 13px; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.review-sec .none { color: var(--text-2); font-size: 13px; }

/* ---------- Overview / status ---------- */
.status-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 26px; max-width: 980px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 2px; padding: 14px 16px; }
.card h4 { margin: 0 0 10px; font-size: 14px; }
.donut-row { display: flex; align-items: center; gap: 16px; }
.legend { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; display: inline-block; border-radius: 2px; }

/* ---------- Flyout ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; justify-content: flex-end; }
.flyout {
  width: min(640px, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: slideIn .18s ease-out;
}
.flyout.wide { width: min(1040px, 100%); }
@keyframes slideIn { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.fly-head { padding: 18px 24px 10px; display: flex; align-items: flex-start; gap: 12px; }
.fly-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.fly-head .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.fly-head .x-btn { margin-left: auto; width: 32px; height: 32px; }
.fly-body { flex: 1; overflow-y: auto; padding: 8px 24px 16px; }
.fly-foot { border-top: 1px solid var(--border); padding: 12px 24px; display: flex; gap: 8px; align-items: center; }
.fly-foot .note { color: var(--text-2); font-size: 12px; margin-left: auto; }
.pick-list { border: 1px solid var(--border); margin-top: 8px; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover { background: var(--row-hover); }
.pick-item.sel { background: var(--primary-soft); }
.pick-item .gi {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff; flex: 0 0 28px;
}
.pick-item .pi-sub { color: var(--text-2); font-size: 12px; }
.tpl-item { padding: 10px 12px; }
.tpl-item .t-name { font-weight: 600; }
.tpl-item .t-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.4; margin-top: 2px; }

.catalog { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; min-height: 0; height: 100%; }
.catalog .cat-list { border: 1px solid var(--border); overflow-y: auto; }
.catalog .cat-list button {
  display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 8px 12px; font-size: 13px;
}
.catalog .cat-list button:hover { background: var(--row-hover); }
.catalog .cat-list button.active { background: var(--primary-soft-2); font-weight: 600; }
.catalog .cat-list .cl-from { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; }
.catalog .set-list { border: 1px solid var(--border); overflow-y: auto; }
.catalog .set-list .sl-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--bg); position: sticky; top: 0; }
.catalog .set-list label { display: flex; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: flex-start; }
.catalog .set-list label:hover { background: var(--row-hover); }
.catalog .set-list label input { margin-top: 3px; accent-color: var(--primary); }
.catalog .set-list .sl-desc { color: var(--text-2); font-size: 12px; margin-top: 2px; line-height: 1.35; }
.fly-body.catalog-body { display: flex; flex-direction: column; gap: 10px; overflow: hidden; }

a.learn { white-space: nowrap; font-size: inherit; }
.catalog .set-list label a.learn { position: relative; z-index: 1; }

/* ---------- Toasts & tooltip ---------- */
.toasts { position: fixed; top: 52px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface); box-shadow: var(--shadow); border-left: 4px solid var(--success); padding: 12px 16px; width: 340px;
  font-size: 13px; animation: slideIn .2s ease-out;
}
.toast b { display: block; margin-bottom: 2px; }
.toast.err { border-left-color: var(--danger); }
.tip {
  position: fixed; z-index: 300; max-width: 360px; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 12.5px; line-height: 1.45; border-radius: 2px; pointer-events: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .sidebar.mobile-open { display: block; position: fixed; top: 85px; bottom: 0; left: 0; z-index: 60; box-shadow: var(--shadow); }
  .mobile-menu { display: inline-flex !important; }
  .setting { grid-template-columns: minmax(0, 1fr); }
  .field { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv .k { margin-top: 6px; }
  .catalog { grid-template-columns: minmax(0, 1fr); }
  .brand { display: none; }
  .content, .page-head, .crumbs { padding-left: 16px; padding-right: 16px; }
  .steps { padding: 0 16px; }
}
.mobile-menu { display: none !important; }
