/* Editing: pencils, edited marks, inline controls, drawer, review modal, save bar. */
.pen { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: none; border-radius: 4px; background: transparent; color: var(--faint); padding: 0; vertical-align: middle; flex: none; }
.pen svg { width: 13px; height: 13px; }
.pen:hover { background: var(--blue-soft); color: var(--blue); }
body:not(.editing) .pen { display: none; }
.card-head .pen { margin-left: -4px; }
.cohort-head .pen { opacity: .5; }
.cohort-head:hover .pen { opacity: 1; }
.block-title .pen { margin-left: auto; }
.edit-toggle { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; background: var(--card); color: var(--text); border: 1px solid var(--border-strong); border-radius: 4px; padding: 5px 12px; font-weight: 700; font-size: 12px; letter-spacing: .5px; }
.edit-toggle svg { width: 13px; height: 13px; }
.edit-toggle:hover { background: var(--slate-soft); }
.edit-toggle.on { background: var(--blue); border-color: #1d4ed8; color: #fff; }
.seg .cnt.edit { background: var(--blue-soft); color: var(--blue); }
.seg button.active .cnt.edit { background: rgba(255,255,255,.25); color: #fff; }

/* pending edits */
.nedit { padding: 0 7px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .3px; white-space: nowrap; background: var(--blue-soft); color: var(--blue); }
.block-title .nedit { text-transform: none; letter-spacing: .3px; }
.kv .v.edited, .var.edited { background: var(--blue-soft); border-radius: 4px; box-shadow: 0 0 0 4px var(--blue-soft); }
.var.edited:has(> .ed-switch.inl) { background: none; box-shadow: none; }   /* a switch shows its own state; the change sits in the card's pending list */
/* Edited marker: a blue left edge drawn like the cards' accent border, so it follows the box's corners
 * (boxes that clip their content keep it inside their border). A row gets one edge on its first cell,
 * over the row line as well, so stacked edited rows join into one bar. */
:is(.banner, .plan, .menuopt, .cohort, .ovr, .block, .step, .istep).edited { position: relative; }
:is(.banner, .plan, .menuopt, .cohort, .ovr, .block, .step, .istep).edited::before { content: ""; position: absolute; inset: -1px; border-left: 3px solid var(--blue); border-radius: inherit; pointer-events: none; }
:is(.banner, .cohort).edited::before { inset: 0; }
.tbl tr.edited > :first-child { position: relative; }
.tbl tr.edited > :first-child::before { content: ""; position: absolute; left: 0; top: -1px; bottom: 0; width: 3px; background: var(--blue); pointer-events: none; }
.draft-changes { border: 1px solid #bcd0fb; border-radius: 6px; padding: 8px 10px; background: color-mix(in srgb, var(--blue-soft) 55%, #fff); }
.draft-changes-title { font-weight: 700; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--blue); margin-bottom: 6px; }
.draft-changes .tbl { background: #fff; }
.draft-changes .tbl td { font-size: 12px; }
.draft-changes .tbl td.path { font-family: var(--mono); color: var(--text); }
.draft-changes .tbl td.act { white-space: nowrap; text-align: right; }
.draft-changes .tbl td.differs { background: var(--amber-soft); }
.draft-changes .tbl td.same-now { color: var(--faint); font-style: italic; }
.draft-changes code { font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; }
.draft-changes .delta { font-size: 11px; margin-top: 2px; }
.draft-changes .delta.add { color: var(--green-dark); }
.draft-changes .delta.rm { color: var(--red); }
.draft-changes .revert { background: none; border: 1px solid var(--border-strong); border-radius: 4px; padding: 2px 8px; font-size: 11px; font-weight: 600; color: var(--muted); }
.draft-changes .revert:hover { background: var(--slate-soft); color: var(--text); }

/* controls */
.ed-in { width: 100%; font: 13px/1.4 var(--sans); padding: 5px 8px; border: 1px solid var(--border-strong); border-radius: 5px; background: #fff; color: var(--text); }
.ed-in:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.ed-in.num { font-family: var(--mono); max-width: 160px; }
.ed-in.sel { width: auto; min-width: 150px; max-width: 100%; }
.ed-duration { display: inline-flex; gap: 6px; }
.ed-duration .num { max-width: 90px; }
.ed-in.url, .ed-in.json, textarea.ed-in { font-family: var(--mono); font-size: 12px; }
textarea.ed-in { resize: vertical; }
.ed-in.invalid { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
/* comma-separated sets (flows, audience tags) */
.ed-tagset { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 4px 5px; border: 1px solid var(--border-strong); border-radius: 5px; background: #fff; min-height: 32px; }
.ed-tagset.open { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.ed-tags { display: contents; }
.ed-tags:empty::before { content: attr(data-empty); color: var(--faint); font-style: italic; font-size: 12px; padding: 0 4px; }
.ed-tag { display: inline-flex; align-items: center; gap: 3px; padding-right: 3px; }
.ed-tag button { border: none; background: none; color: inherit; opacity: .55; font-size: 13px; line-height: 1; padding: 0 3px; border-radius: 999px; cursor: pointer; }
.ed-tag button:hover { opacity: 1; background: color-mix(in srgb, currentColor 15%, transparent); }
.ed-tag-plus { width: 22px; height: 22px; border: 1px dashed var(--border-strong); border-radius: 999px; background: none; color: var(--blue); font: 700 14px/1 var(--sans); cursor: pointer; }
.ed-tag-plus:hover, .ed-tagset.open .ed-tag-plus { border-style: solid; border-color: var(--blue); background: var(--blue-soft); }
.ed-tag-menu { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 2px; padding-top: 6px; border-top: 1px dashed var(--border); }
.ed-tag-menu[hidden] { display: none; }
.ed-tag-menu .opts { display: flex; flex-wrap: wrap; gap: 5px; }
.ed-tag-menu .opts .pill { border: 1px solid transparent; cursor: pointer; }
.ed-tag-menu .opts .pill:hover, .ed-tag-menu .opts .pill:focus-visible { border-color: currentColor; outline: none; }
.ed-tag-menu .custom { display: flex; gap: 6px; align-items: center; }
.ed-tag-menu .custom .ed-in { max-width: 220px; padding: 3px 8px; font-family: var(--mono); font-size: 12px; }
.ed-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; padding-top: 4px; font-weight: 700; font-size: 11px; color: var(--muted); }
.ed-switch input { display: none; }
.ed-switch i { width: 34px; height: 18px; border-radius: 999px; background: #c9cfd6; position: relative; transition: background .15s; }
.ed-switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: left .15s; }
.ed-switch input:checked + i { background: var(--green); }
.ed-switch input:checked + i::after { left: 18px; }
.ed-switch input:checked ~ span { color: var(--green-dark); }
.ed-switch.inl { padding-top: 0; vertical-align: middle; }   /* on the page, next to the values it switches */
.ed-ops { display: inline-flex; gap: 2px; align-items: center; }
.ed-op { background: none; border: 1px solid transparent; border-radius: 4px; color: var(--faint); font-size: 13px; line-height: 1; padding: 4px 6px; }
.ed-op:hover { background: var(--slate-soft); color: var(--text); }
.ed-op.remove:hover { background: var(--red-soft); color: var(--red); }
.ed-op.add, .ed-op.addloc { color: var(--blue); font-weight: 700; font-size: 12px; }
.ed-row:not(:hover) > .ed-ops .remove, .ed-li:not(:hover) > .ed-ops .remove, .ed-group > summary:not(:hover) .remove, .ed-item > summary:not(:hover) .remove { opacity: .25; }

/* generated form */
.ed-fields { display: flex; flex-direction: column; gap: 8px; }
.ed-row { display: grid; grid-template-columns: minmax(120px, 170px) 1fr auto; gap: 4px 12px; align-items: start; }
.ed-k { color: var(--muted); font-weight: 600; padding-top: 6px; }
.ed-k small { display: block; font-family: var(--mono); font-weight: 400; color: var(--faint); font-size: 10px; word-break: break-word; }
.ed-v { min-width: 0; }
.ed-group, .ed-item { border: 1px solid var(--border); border-radius: 6px; background: #fbfcfd; }
.ed-group > summary, .ed-item > summary { cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-weight: 700; user-select: none; list-style: none; }
.ed-group > summary::-webkit-details-marker, .ed-item > summary::-webkit-details-marker { display: none; }
.ed-group > summary small { font-family: var(--mono); font-weight: 400; color: var(--faint); font-size: 10px; }
.ed-sum { color: var(--muted); font-weight: 500; font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-group-body, .ed-item-body { padding: 8px 10px 10px; border-top: 1px solid var(--border); }
.ed-item > summary .n, .ed-li .n { font-family: var(--mono); font-size: 11px; color: var(--faint); min-width: 16px; text-align: right; }
.ed-list { display: flex; flex-direction: column; gap: 6px; }
.ed-li { display: flex; align-items: center; gap: 8px; }
.ed-li .ed-v { flex: 1; }
.ed-bundle { display: flex; flex-direction: column; gap: 4px; }
.ed-bundle .loc { font-family: var(--mono); font-size: 10px; color: var(--faint); text-transform: uppercase; min-width: 22px; }
.ed-bundle .loc-in { max-width: 72px; font-family: var(--mono); }
.ed-ovr { border: 1px dashed var(--ovr); border-radius: 6px; padding: 6px 10px 10px; margin: 0; background: color-mix(in srgb, var(--ovr) 6%, #fff); }
.ed-empty { color: var(--muted); font-style: italic; padding: 4px 0; }
.ed-addkey { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 12px; white-space: nowrap; flex-wrap: wrap; }
.ed-addkey select { font: inherit; padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: 5px; background: #fff; }
.ed-addkey .ovr-key { width: 200px; font-family: var(--mono); font-size: 12px; padding: 4px 8px; }
.ed-json textarea { width: 100%; min-height: 60vh; }
.ed-json-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.ed-json-foot .err { color: var(--red); font-size: 12px; }
.spacer { flex: 1; }

.btn-blue { background: var(--blue); color: #fff; border: 1px solid #1d4ed8; border-radius: 4px; padding: 6px 12px; font-weight: 700; font-size: 12px; }
.btn-blue:hover { background: #1d4ed8; }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--border-strong); border-radius: 4px; padding: 6px 12px; font-weight: 600; font-size: 12px; }
.btn-ghost:hover { background: var(--slate-soft); }
.btn-ghost.small { padding: 3px 8px; font-size: 11px; margin-top: 4px; }
.btn-red { background: var(--red); color: #fff; border: 1px solid #b23636; border-radius: 4px; padding: 6px 12px; font-weight: 700; font-size: 12px; }
.btn-red:hover { background: #b23636; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* drawer */
.drawer { position: fixed; top: 64px; right: 0; bottom: 0; width: 560px; max-width: 100vw; background: var(--card); border-left: 1px solid var(--border); box-shadow: -12px 0 40px rgba(0,0,0,.15); z-index: 60; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--blue-soft); }
.drawer-title { font-weight: 800; font-size: 14px; }
.drawer-path { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.drawer .x, .modal .x { margin-left: auto; background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px; }
.drawer .x:hover, .modal .x:hover { color: var(--text); }
.drawer-tabs { display: flex; align-items: center; gap: 2px; padding: 6px 14px 0; border-bottom: 1px solid var(--border); }
.drawer-tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 6px 10px; font-weight: 700; color: var(--muted); }
.drawer-tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }
.drawer-tabs .drawer-edits { margin-left: auto; }
.drawer-body { flex: 1; overflow: auto; padding: 14px; }
.env-strip { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 14px; border-bottom: 1px solid var(--border); background: #fbfcfd; font-size: 12px; }
.env-strip .lbl { color: var(--muted); font-weight: 600; }
.env-strip .sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 6px; }
.env-btn { background: var(--card); border: 1px solid var(--border-strong); border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 11px; color: var(--text); }
.env-btn:hover:not(:disabled) { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.env-btn i { font-style: normal; color: var(--faint); margin-left: 4px; }
.env-strip .note { margin-left: auto; color: var(--green-dark); font-weight: 600; }
.drawer-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); background: #fbfcfd; }
@media (min-width: 1400px) { .drawer-open .content, .drawer-open .sub, .drawer-open .apps, .drawer-open .toolbar { margin-right: 560px; } }

/* save bar */
.savebar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 70; display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 16px; background: var(--nav); color: #fff; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3); font-size: 13px; white-space: nowrap; }
.drawer-open .savebar { left: calc((100vw - 560px) / 2); }
.savebar .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.35); flex: none; }
.savebar.prod > .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(214,69,69,.35); }
.savebar .env { font-weight: 800; letter-spacing: .5px; }
.savebar.prod > .t .env { color: #ff8a8a; }
.savebar .warn { margin-left: 10px; color: #ffc46b; font-size: 12px; }
.savebar .ghost { background: transparent; color: #cdd3db; border: 1px solid #3a3f47; border-radius: 4px; padding: 6px 12px; font-weight: 600; font-size: 12px; }
.savebar .ghost:hover { color: #fff; border-color: #6b7280; }
.savebar .btn-green svg { width: 12px; height: 12px; }

/* review modal */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(20,24,30,.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--card); border-radius: 10px; width: min(880px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); overflow: hidden; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 10px; }
.modal-title { font-weight: 800; font-size: 15px; }
.modal-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.modal-sub b.prod { color: var(--red); }
.modal-sub code { font-family: var(--mono); }
.modal-body { padding: 14px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 10px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; background: #fbfcfd; }
.callout { border-radius: 6px; padding: 8px 12px; font-size: 12.5px; border: 1px solid; }
.callout b { display: block; }
.callout.red { background: var(--red-soft); border-color: #f3b4b4; color: #8f2626; }
.callout.amber { background: var(--amber-soft); border-color: #f1d9a6; color: #7a4d06; }
.callout.blue { background: var(--blue-soft); border-color: #bcd0fb; color: #1e3a8a; }
.also { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; background: #fbfcfd; }
.also .lbl { font-weight: 700; color: var(--muted); }
.also-env { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; padding: 3px 10px; border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; user-select: none; }
.also-env:has(input:checked) { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.also-env.prod:has(input:checked) { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.also-env.off { opacity: .5; cursor: default; }
.also-env i { font-style: normal; color: var(--faint); }
.also .hint { margin-left: auto; }
.req-env { display: flex; align-items: center; gap: 10px; font-size: 13px; padding-top: 6px; border-top: 1px solid var(--border); }
.req-env b.prod { color: var(--red); }
.req + .req { margin-top: 4px; }
.ed-ovr legend { padding: 0 4px; display: flex; align-items: center; gap: 4px; }
.ed-ovr legend .ed-op { opacity: .35; }
.ed-ovr:hover legend .ed-op { opacity: 1; }
.ack { display: flex; align-items: center; gap: 8px; font-weight: 600; color: #8f2626; }
.req { display: flex; flex-direction: column; gap: 8px; }
.req-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req-line code { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.req .tbl td { font-size: 12px; }
.req .tbl td.path { font-family: var(--mono); white-space: nowrap; }
.req .tbl code { font-family: var(--mono); font-size: 11.5px; overflow-wrap: anywhere; }
.inline-json summary { cursor: pointer; color: var(--blue); font-weight: 600; }
.inline-json pre { margin: 6px 0 0; font: 11.5px/1.5 var(--mono); max-height: 300px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 4px; }
.modal .raw-json pre { white-space: pre-wrap; word-break: break-all; max-height: 50vh; }
@media (max-width: 760px) {
  .savebar { left: 10px; right: 10px; transform: none; white-space: normal; flex-wrap: wrap; }
  .drawer { top: 0; width: 100vw; }
}
.savebar[hidden], .drawer[hidden], .modal[hidden] { display: none; }
/* saving progress */
.progress { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.progress li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fbfcfd; }
.progress li .ico { width: 20px; text-align: center; font-weight: 800; color: var(--muted); }
.progress li .msg { color: var(--muted); font-size: 12px; }
.progress li.saved .ico, .progress li.verified .ico, .progress li.ready .ico { color: var(--green-dark); }
.progress li.verified { border-color: var(--green-border); background: var(--green-soft); }
.progress li.failed { border-color: #f3b4b4; background: var(--red-soft); }
.progress li.failed .ico, .progress li.failed .msg { color: var(--red); }
.progress li.unverified { border-color: #f1d9a6; background: var(--amber-soft); }
.progress li.unverified .ico, .progress li.unverified .msg { color: var(--amber); }
.progress li.checking .ico, .progress li.saving .ico { color: var(--blue); animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress b.prod { color: var(--red); }
.undo-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* draft tabs in the save bar */
.savebar { padding-left: 8px; max-width: calc(100vw - 28px); }
.savebar { flex-wrap: wrap; }
.savebar .dtabs { display: flex; flex-wrap: wrap; gap: 4px; max-width: calc(100vw - 360px); }
.savebar .dtab { display: inline-flex; align-items: center; gap: 7px; background: transparent; color: #cdd3db; border: 1px solid transparent; border-radius: 7px; padding: 6px 10px; font-size: 12.5px; white-space: nowrap; }
.savebar .dtab:hover { background: rgba(255,255,255,.08); color: #fff; }
.savebar .dtab.active { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.18); color: #fff; }
.savebar .dtab .env { font-weight: 800; letter-spacing: .5px; }
.savebar .dtab.prod .env { color: #ff8a8a; }
.savebar .dtab.prod .dot { background: var(--red); box-shadow: 0 0 0 3px rgba(214,69,69,.35); }
.savebar .dtab .n { padding: 0 6px; border-radius: 999px; background: rgba(255,255,255,.15); font-family: var(--mono); font-size: 10px; font-weight: 700; }
.savebar .dtab.active .n { background: var(--blue); }
.savebar .dtab.active.prod .n { background: var(--red); }
.savebar .pick { color: #9aa3af; font-size: 12px; padding: 0 6px; }
.apps button .draft-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
