:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1f2933; --muted: #56616d; --line: #e1e5ea;
  --accent: #2563eb; --accent-soft: #e8efff; --ok: #157347; --ok-soft: #e3f4ea; --warn: #9a6200; --warn-soft: #fff4dc;
  --bad: #b42318; --bad-soft: #fdecea; --chip: #eef1f4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { width: 18px; height: 18px; background: linear-gradient(135deg, #2563eb, #7c3aed 50%, #f59e0b); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.muted { color: var(--muted); font-weight: 400; }
.portal-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.shell { display: grid; grid-template-columns: 200px 1fr; min-height: calc(100vh - 53px); }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.side a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.side a:hover { background: var(--chip); }
.side a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-note { margin-top: auto; color: var(--muted); font-size: 12px; line-height: 1.4; padding: 8px; }
main { padding: 20px 24px; min-width: 0; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 22px 0 8px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 12px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.card .n { font-size: 22px; font-weight: 700; }
.card .l { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 53px; z-index: 1; }
tbody tr:hover { background: #fafcff; }
.tbl-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.tbl-wrap th { top: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); white-space: nowrap; }
.pill.proposed { background: var(--accent-soft); color: var(--accent); }
.pill.confirmed, .pill.mapped { background: var(--ok-soft); color: var(--ok); }
.pill.needs_decision, .pill.unmapped { background: var(--warn-soft); color: var(--warn); }
.pill.missing, .pill.rejected { background: var(--bad-soft); color: var(--bad); }
.pill.inferred { background: var(--warn-soft); color: var(--warn); }
.pill.chrome { background: var(--chip); color: var(--muted); }
input[type=text], input[type=search], select, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0; }
input[type=text]:focus, input[type=search]:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button { font: inherit; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
/* UX-08: disabled = grey dashed outline, never a pale version of the enabled colour */
button:disabled, button.primary:disabled { background: #f2f4f7; color: #6b7480; border: 1px dashed #b9c1cb; cursor: not-allowed; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.grow { flex: 1; }
.switch { position: relative; width: 34px; height: 20px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cdd3da; border-radius: 20px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); }
.editor { display: grid; grid-template-columns: minmax(520px, 46%) 1fr; gap: 16px; align-items: start; }
.editor .slots { max-height: calc(100vh - 190px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.editor .slots th { top: 0; }
.area-row td { background: #f3f5f8; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.slot-off td:not(:first-child) { opacity: .5; }
.preview { position: sticky; top: 70px; }
.preview iframe { width: 100%; height: calc(100vh - 190px); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.row-actions { display: flex; gap: 6px; }
.small { font-size: 12px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 4px; }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.adv[open] { padding-bottom: 4px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 8px 14px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none;
  z-index: 30; max-width: calc(100vw - 24px); display: flex; align-items: center; gap: 12px; }
#toast.show.action { pointer-events: auto; }
#toast button { background: transparent; color: #fff; border-color: #8b97a4; padding: 2px 10px; font-weight: 600; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }
.empty { padding: 20px; color: var(--muted); }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } .preview { position: static; } }
.top-right { display: flex; align-items: center; gap: 16px; }
.userbar { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.userbar .who { text-align: right; line-height: 1.2; }
.userbar .who strong { color: var(--ink); display: block; }
.badge-super { background: #f3e8ff; color: #6b21a8; }
.super-link { color: #6b21a8 !important; }
.gate { display: grid; place-items: center; min-height: calc(100vh - 53px); padding: 24px; }
.gate .box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(420px, 100%); }
.gate h1 { margin-bottom: 6px; }
.gate label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.gate input { width: 100%; padding: 9px 10px; font-size: 15px; }
.gate .actions { display: flex; gap: 8px; margin-top: 16px; }
.gate .pick { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.gate .pick button { text-align: left; padding: 10px 12px; }
.err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 1em; }

/* plan 12e/12f: screens CRUD, tabs, phase dots, viewer-only shell */
.shell.viewer { grid-template-columns: 1fr; }
.shell.viewer .side { display: none; }
/* View page: the menu folds away so the screen / dashboard gets the whole width ("☰ Menu" brings it back) */
.shell.focus { grid-template-columns: 1fr; }
.shell.focus .side { display: none; }
.shell.focus main, .shell.viewer main { padding: 12px 16px; }
.shell.focus .viewer-frame, .shell.viewer .viewer-frame { height: calc(100vh - 118px); }
.viewer-frame { width: 100%; height: calc(100vh - 130px); border: 1px solid var(--line); border-radius: 8px; background: #f6f7f9; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; }
.tabs a { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
a.btn { display: inline-block; padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); text-decoration: none; background: var(--panel); font-size: 13px; }
a.btn:hover { background: var(--chip); }
button.danger { color: var(--bad); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.dot-slate { background: #64748b; } .dot-blue { background: #2f6fe4; } .dot-violet { background: #7c4ddb; } .dot-amber { background: #d48a04; }
.dot-green { background: #16935a; } .dot-red { background: #d43c3c; } .dot-teal { background: #0f9488; } .dot-pink { background: #d4387f; }

/* plan 13: per-object binding picker */
.objbind { margin: 4px 0 2px; padding: 4px 0 0; border-top: 1px dashed var(--line); }
.objbind-row { margin: 2px 0; }
.section-row td { background: #f3f6fb; border-top: 2px solid var(--line); }

/* plan 19c (builder A): admin shell UX */
a.btn:hover, .side a:hover, .tabs a:hover { text-decoration: none; }
/* UX-28: skip link, visible only on keyboard focus */
.skip { position: absolute; left: 8px; top: -40px; z-index: 50; background: var(--panel); padding: 6px 10px; border: 1px solid var(--accent); border-radius: 6px; }
.skip:focus { top: 8px; }
/* UX-05: menu groups */
.side-group { margin: 12px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.side-group:first-child { margin-top: 0; }
/* UX-02: codes and ids only with "Technical details" (or Inspect) on */
.tech { display: none !important; }
body.show-tech .tech { display: revert !important; }
body.show-tech code.tech, body.show-tech span.tech { display: inline !important; }
/* UX-22: retired ("x …") pipelines dimmed; tighter pipeline rows */
.retired { opacity: .6; }
details.pipe { padding: 6px 12px; margin-bottom: 6px; }
details.pipe > summary { padding: 2px 0; }
/* UX-06: recently deleted */
details.deleted { margin-top: 14px; }
details.deleted summary { cursor: pointer; color: var(--muted); }
details.deleted ul { list-style: none; padding: 0; margin: 8px 0 0; }
details.deleted li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
/* UX-26: "or" divider + full-width HubSpot button */
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0 10px; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.gate .wide { width: 100%; padding: 9px 12px; }
.loading { color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.menu-btn { white-space: nowrap; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }

/* UX-01: phone. The page never scrolls sideways; the side menu is a drawer under "☰ Menu" in the header */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .top-right { flex-wrap: wrap; gap: 8px; justify-content: flex-end; flex: 1 1 auto; min-width: 0; }
  .userbar { flex-wrap: wrap; gap: 6px; }
  .userbar .who .email { display: none; }
  .portal-pick.single { display: none !important; }
  .portal-pick .portal-label { display: none; }
  .portal-pick select { max-width: 150px; }
  .shell, .shell.focus { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .side { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(260px, 82vw); overflow-y: auto;
    padding-top: calc(14px + env(safe-area-inset-top, 0px)); transform: translateX(-105%); transition: transform .15s;
    box-shadow: 2px 0 12px rgba(16, 24, 40, .18); }
  .shell.focus .side { display: flex; }
  .shell.viewer .side, .shell.focus.viewer .side { display: none; }
  .shell:not(.menu-open) .side { visibility: hidden; }
  .shell.menu-open .side { transform: none; visibility: visible; }
  .shell.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(16, 24, 40, .3); z-index: 15; }
  .menu-toggle { display: none; }
  main, .shell.focus main, .shell.viewer main { padding: 12px; }
  .tabs { overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
  .panel { overflow-x: auto; }
  .two-col, .editor { grid-template-columns: minmax(0, 1fr); }
  .editor .slots, .preview iframe { max-height: none; height: auto; }
  .preview iframe { height: 70vh; }
  .shell.focus .viewer-frame, .shell.viewer .viewer-frame, .viewer-frame { height: calc(100vh - 150px); }
  th { top: 0; }
  input[type=text], input[type=search], input[type=email], select, textarea { max-width: 100%; }
  .toolbar > * { max-width: 100%; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #toast { left: 12px; right: 12px; transform: none; justify-content: space-between; }
}
@media (min-width: 761px) { .menu-btn { display: none; } }
