/* Dialog structure (modal): .setup-dialog > .dialog-heading (h2 + close .icon-button) > body > .dialog-actions
   or .desk-editor-footer. Dialogs holding a form get a sticky header/footer so long forms scroll between them.
   Drawers (.desk-editor-drawer) float at the right edge with the same header/footer. */
.setup-dialog:has(:where(.desk-form, .sequence-form, .workforce-form)),
.setup-dialog.desk-editor-drawer, #workflow-preview:has(.workflow-preview-form) {
  --editor-space: 24px;
  padding: var(--editor-space);
  max-block-size: calc(100dvh - 32px);
  border-color: var(--dialog-border, transparent);
  border-radius: var(--radius-xl, 16px);
  background: var(--elevated, var(--surface));
  scroll-padding-block: 72px 72px;
}
.setup-dialog:is(.desk-editor-drawer, :has(:where(.desk-form, .sequence-form, .workforce-form))) > .dialog-heading {
  position: sticky;
  z-index: 5;
  inset-block-start: calc(-1 * var(--editor-space));
  margin: calc(-1 * var(--editor-space)) calc(-1 * var(--editor-space)) 8px;
  min-height: 64px;
  padding: 16px 16px 12px var(--editor-space);
  border-bottom: 1px solid transparent;
  background: var(--elevated, var(--surface));
}
.setup-dialog:is(.desk-editor-drawer, :has(:where(.desk-form, .sequence-form, .workforce-form))) > .dialog-heading h2 {
  min-width: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.setup-dialog .dialog-heading .icon-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.setup-dialog .dialog-heading .icon-button:hover { background: var(--hover); color: var(--ink); }
/* Drawer: floating panel on the right, full height, 16px radius, slides in. */
dialog.setup-dialog.desk-editor-drawer {
  inset: 8px 8px 8px auto;
  margin: 0;
  width: min(560px, calc(100vw - 16px));
  max-inline-size: calc(100vw - 16px);
  height: calc(100dvh - 16px);
  max-block-size: calc(100dvh - 16px);
  border-width: 1px;
  border-radius: var(--radius-xl, 16px);
  box-shadow: var(--shadow-dialog);
}
dialog.setup-dialog.desk-editor-drawer > .dialog-heading { border-bottom-color: var(--line); margin-bottom: 20px; }
dialog.setup-dialog.desk-editor-drawer[open] { animation: desk-drawer-in 180ms ease-out; }
dialog.setup-dialog:not(.desk-editor-drawer)[open] { animation: desk-dialog-in 140ms ease-out; }
@keyframes desk-drawer-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes desk-dialog-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@media (prefers-reduced-motion: reduce) { dialog.setup-dialog[open] { animation: none; } }
dialog.setup-dialog.desk-editor-drawer:is(#report-editor, #kb-center-dialog, #data-connectors-dialog) { width: min(690px, calc(100vw - 16px)); }
dialog.setup-dialog.desk-compose-dialog { width: min(620px, calc(100vw - 24px)); }

.setup-dialog :is(.desk-form, .sequence-form, .workforce-form), #workflow-preview .workflow-preview-form { min-width: 0; gap: 14px; }
.setup-dialog > .desk-form + .desk-form { padding-top: 16px; border-top: 1px solid var(--line); }
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) label {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) label > :where(input:not([type="checkbox"], [type="radio"], [type="color"]), textarea, select) {
  width: 100%;
}
.setup-dialog :is(.desk-form, .workforce-form) label:has(> input:is([type="checkbox"], [type="radio"])):not(:has(> select, > textarea)) {
  display: flex;
  align-items: start;
  gap: 8px;
  font-weight: 400;
  line-height: 1.4;
}
.setup-dialog :is(.desk-form, .workforce-form) label > input:is([type="checkbox"], [type="radio"]) {
  flex: 0 0 auto;
  width: 16px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}
.setup-dialog p.form-error:not(:empty) { color: var(--danger-ink); overflow-wrap: anywhere; }
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) > .button.primary[type="submit"] { justify-self: end; }
/* Grouped fields inside dialogs: a quiet 12px-radius section with a 13px/600 legend. */
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) > fieldset:not([class]), .desk-editor-section, .ticket-config-row {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  background: var(--surface);
}
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) legend {
  padding-inline: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
/* Only carded fieldsets notch their legend into the border; others align with field labels. */
.setup-dialog :is(.desk-form, .sequence-form, .workforce-form) > fieldset:not([class]) > legend { padding-inline: 6px; }
.desk-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.desk-editor-footer {
  position: sticky;
  z-index: 3;
  inset-block-end: calc(-1 * var(--editor-space));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 8px calc(-1 * var(--editor-space)) calc(-1 * var(--editor-space));
  padding: 16px var(--editor-space);
  border-top: 1px solid var(--line);
  background: var(--elevated, var(--surface));
}
.desk-editor-footer:not(:has(.button:not([hidden]))) { display: none; }
.desk-editor-footer .button.danger-button { margin-inline-end: auto; }
.desk-editor-drawer .contact-form-section, .desk-editor-drawer .report-chart-editor { border: 1px solid var(--line); border-radius: var(--radius-lg, 12px); background: var(--inset); }
.desk-editor-drawer .contact-form-section { margin-top: 12px; }
.desk-editor-drawer .report-chart-editor { grid-template-columns: repeat(3, minmax(0, 1fr)) 32px; padding: 12px; }
.report-chart-editor label:has([data-config="metric"]) { grid-column: span 2; }
.report-chart-editor [data-remove-chart] { grid-area: 1 / 4; }
.desk-editor-drawer .contact-form-section > summary { color: var(--ink); font-weight: 600; }
.desk-editor-drawer .company-contacts { margin-block-start: 25px; }
#ticket-edit-form :is([data-ticket-attributes], [data-ticket-tracker]):not(:empty) { display: grid; gap: 10px; }
#ticket-dialog-body :is([data-ticket-fields], [data-ticket-states]) { display: grid; gap: 7px; }
#ticket-dialog-body :is([data-ticket-fields], [data-ticket-states]) h3 { margin: 7px 0 0; font-size: 14px; }

.desk-writing-surface { min-width: 0; overflow: hidden; border: 1px solid var(--control-line); border-radius: var(--radius-lg, 12px); background: var(--surface); }
.desk-writing-surface:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring, transparent); }
.desk-writing-surface :is(input, textarea):focus-visible { box-shadow: none; }
.setup-dialog .desk-writing-surface label > textarea {
  display: block;
  min-height: 160px;
  padding: 12px 13px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  font-size: 14px;
}
.setup-dialog .desk-writing-surface .desk-writing-subject {
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  padding-inline: 12px;
  border-bottom: 1px solid var(--soft-line);
}
.setup-dialog .desk-writing-surface .desk-writing-subject input { padding-inline: 1px; border: 0; border-radius: 0; outline: none; background: transparent; }
.desk-writing-surface .saved-field-controls { padding: 7px 9px; border-top: 1px solid var(--soft-line); background: var(--inset); }
.desk-writing-surface .saved-prompt-tools { display: flex; flex: 1 1 190px; align-items: center; gap: 6px; min-width: 0; }
.desk-writing-surface .saved-prompt-tools input { padding: 5px 7px; }
.desk-compose-dialog .saved-editor-fields { grid-template-columns: minmax(0, 1fr) minmax(195px, .5fr); }
#contact-rule-editor .contact-popover-footer { position: sticky; inset-block-end: -9px; padding: 8px 9px; margin: 7px -9px -9px; background: var(--surface); }

.desk-content-editor { min-width: 0; }
.desk-content-editor-header {
  position: sticky;
  z-index: 3;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 9px 14px;
  padding: 8px 0 11px;
  background: var(--page);
}
.desk-content-editor-header :is(.engagement-editor-header, .site-guide-heading) { display: flex; align-items: center; gap: 7px; min-width: 0; margin: 0; }
.desk-content-editor-header h3 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.desk-content-editor-header :is(.engagement-actions, .site-guide-actions) { margin: 0; }
.desk-content-editor-grid {
  display: grid;
  grid-template-columns: minmax(225px, 275px) minmax(0, 1fr);
  min-width: 0;
  border: 1px solid var(--desk-divider);
  border-radius: var(--desk-panel-radius);
  background: var(--surface);
}
.desk-content-editor .desk-content-editor-settings { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 11px; padding: 13px; border-inline-end: 1px solid var(--desk-divider); }
.desk-content-editor-settings h4 { margin: 0; font-size: 14px; }
.desk-content-editor-settings .engagement-fields { grid-template-columns: minmax(0, 1fr); }
.desk-content-editor-main { min-width: 0; padding: 13px; background: var(--inset); border-radius: 0 var(--desk-panel-radius) var(--desk-panel-radius) 0; }
.desk-content-editor-main :is(.engagement-edit-steps, .site-guide-steps) { margin-top: 0; }
.desk-content-editor-main :is(.engagement-edit-steps fieldset, .site-guide-step) { min-width: 0; background: var(--surface); }
#engagement-view:has(.desk-content-editor) > .people-toolbar, #site-guides-view:has(.desk-content-editor) > .people-toolbar { display: none; }
#kb-editor .kb-write-area { border-color: var(--desk-divider); box-shadow: 0 3px 13px color-mix(in srgb, var(--shadow) 35%, transparent); }
#kb-editor .kb-article-details { background: var(--desk-side); }
#kb-editor .kb-format-toolbar { background: var(--inset); }
.email-setup-card .desk-form + .desk-form { margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--desk-divider); }

@media (max-width: 810px) {
  .desk-content-editor-grid { grid-template-columns: minmax(0, 1fr); }
  .desk-content-editor .desk-content-editor-settings { border-inline-end: 0; border-bottom: 1px solid var(--desk-divider); }
  .desk-content-editor-main { border-radius: 0 0 var(--desk-panel-radius) var(--desk-panel-radius); }
  .desk-content-editor-header { position: static; }
}
@media (max-width: 510px) {
  .desk-editor-grid, .desk-compose-dialog .saved-editor-fields { grid-template-columns: minmax(0, 1fr); }
  .desk-editor-drawer .report-chart-editor { grid-template-columns: minmax(0, 1fr); }
  .report-chart-editor label:has([data-config="metric"]) { grid-column: auto; }
  .report-chart-editor [data-remove-chart] { grid-area: auto; }
  .desk-compose-dialog .desk-writing-surface label > textarea { min-height: 130px; }
}
