/* Contacts, companies, segments, custom objects, contact profile and people & data settings.
   Intercom-style area overrides. Loaded after every other desk stylesheet. */

/* ---------- Area icons: inline SVG (see peopleIcon in contact-fields.js), same 18px box as sprite icons ---------- */
.pd-icon { display: inline-block; flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.workspace .segment-link .pd-icon { color: var(--muted); }
.workspace .segment-link:is([aria-pressed="true"], [aria-current="page"]) .pd-icon { color: var(--ink); }
.desk-empty-icon .pd-icon { color: var(--muted); }
.button .pd-icon { margin-inline-start: -2px; color: var(--muted); }

/* ---------- Contacts page frame: header and filters stay put, the table scrolls under a sticky header ---------- */
#contacts-view .people-content { display: flex; flex-direction: column; min-height: 0; padding-bottom: 20px; }
#contacts-view :is(#contact-people-pane, #company-pane):not([hidden]) { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
#contacts-view :is(#contacts-results, #company-results) { flex: 0 1 auto; min-height: 168px; overflow: auto; overscroll-behavior: contain; }
#contacts-view :is(#contacts-results, #company-results):has(> .desk-empty) { min-height: 0; overflow: visible; }

/* ---------- Segments sidebar ---------- */
#contacts-view .segments-sidebar { display: flex; flex-direction: column; gap: 2px; }
#contacts-view .segments-sidebar > h2 { flex: none; }
#contacts-view #segment-list { display: grid; gap: 2px; }
#contacts-view #segment-list .segment-group-heading { margin: 14px 8px 4px; }
#contacts-view .segment-empty { margin: 0; padding: 4px 8px 6px; color: var(--quiet); font-size: 12px; line-height: 1.45; }
#contacts-view .segments-sidebar .segment-link { width: 100%; }

/* ---------- Page header + filter bar ---------- */
#contacts-view .people-toolbar { flex: none; min-height: 32px; margin-bottom: 12px; }
#contacts-view .people-toolbar h2 { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
#contacts-view .contact-directory-actions { gap: 8px; }

#contacts-view .people-filter-bar { flex: none; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
#contacts-view .people-filter-bar > .people-filters { flex: 1 1 auto; min-width: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
#contacts-view .people-filter-bar > .segment-actions { flex: none; margin: 0; gap: 8px; }
#contacts-view .people-filters .filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
#contacts-view .people-filters .filter-chip-row { display: contents; }
#contacts-view .people-filters .filter-group-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 0; }
#contacts-view .people-filters .nested-filter-group { display: inline-flex; max-width: 100%; margin: 0; padding: 3px 4px 3px 3px; border: 1px dashed var(--control-line); border-radius: 999px; background: transparent; }
#contacts-view .people-filters .filter-chip {
  min-height: 30px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--hover);
  transition: background-color 120ms ease;
}
#contacts-view .people-filters .filter-chip:hover { background: var(--selected); }
#contacts-view .people-filters .filter-chip-main {
  gap: 6px;
  min-height: 28px;
  padding: 0 4px 0 10px;
  border-radius: 999px 0 0 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
#contacts-view .people-filters .filter-chip-main:hover { background: transparent; color: var(--muted); }
#contacts-view .people-filters .filter-chip-main strong { color: var(--ink); font-weight: 500; }
#contacts-view .people-filters .filter-chip-main .icon { color: var(--muted); transform: scale(.85); }
#contacts-view .people-filters :is(.filter-chip-remove, .filter-group-remove) {
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  margin-inline-end: 4px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
}
#contacts-view .people-filters :is(.filter-chip-remove, .filter-group-remove):hover { background: var(--line); color: var(--ink); }
#contacts-view .people-filters :is(.filter-chip-remove, .filter-group-remove) .icon { transform: scale(.72); }
#contacts-view .people-filters select.filter-join {
  width: auto;
  min-width: 0;
  min-height: 24px;
  height: 24px;
  padding: 0 6px 0 9px;
  border-color: var(--control-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 22px;
  letter-spacing: .02em;
}
#contacts-view .people-filters select.filter-join::picker-icon { font-size: 10px; }
#contacts-view .people-filters .filter-join-label { padding: 0 2px; color: var(--quiet); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
#contacts-view .people-filters .filter-text-action {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}
#contacts-view .people-filters .filter-text-action:hover:enabled { background: var(--accent-soft); color: var(--accent-hover); }
#contacts-view .people-filters .filter-text-action.filter-add-group { color: var(--muted); }
#contacts-view .people-filters .filter-text-action.filter-add-group:hover:enabled { background: var(--hover); color: var(--ink); }
#contacts-view .people-filters .filter-text-action:disabled { color: var(--quiet); cursor: default; }
#contacts-view #contact-search-error { flex: none; margin: 10px 0 0; }

/* ---------- Results toolbar + contextual bulk bar ---------- */
#contacts-view .people-results-toolbar { flex: none; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin: 12px 0; }
#contacts-view .people-results-summary { display: flex; align-items: center; gap: 4px 8px; flex: 1 1 auto; min-width: 0; }
#contacts-view .people-results-summary > p { flex: 0 1 auto; color: var(--ink); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
#contacts-view .people-results-summary > .button.ghost { color: var(--muted); }
#contacts-view .people-results-actions {
  --desk-field-height: 32px;
  --desk-field-font-size: 13px;
  --desk-field-padding: 5px 9px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
#contacts-view .people-results-actions .search-field { flex: 0 1 220px; width: 220px; min-width: 140px; height: 32px; padding-inline: 9px; }
#contacts-view .search-field input:focus-visible, .contact-popover .search-field input:focus-visible { border: 0; box-shadow: none; }
#contacts-view .people-results-actions select { width: auto; }
#contacts-view .people-results-actions .company-segment-select { display: inline-flex; }
#contacts-view #company-filter-status:empty { display: none; }

/* The bulk bar replaces the toolbar row while rows are selected, so the table never shifts under the pointer. */
#contact-people-pane:has(> #contact-bulk-actions:not([hidden])) > .people-results-toolbar { display: none; }
#contacts-view .contact-bulk-actions:not([hidden]) {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-height: 32px;
  margin: 12px 0;
  padding: 1px 2px 1px 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
}
#contacts-view #contact-selection-count { margin-inline-end: 6px; color: var(--ink); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
#contacts-view #clear-contact-selection { margin-inline-start: auto; color: var(--ink); }
#contacts-view #clear-contact-selection:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- Contacts + companies tables ---------- */
#contacts-view :is(#contacts-results, #company-results) { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
#contacts-view :is(#contacts-results, #company-results) .people-table { border-collapse: separate; border-spacing: 0; }
#contacts-view :is(#contacts-results, #company-results) .people-table thead th {
  position: sticky;
  z-index: 2;
  top: 0;
  height: 40px;
  padding: 0 12px;
  border-bottom: 0;
  box-shadow: inset 0 -1px 0 var(--line);
  background: var(--inset);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: start;
}
#contacts-view :is(#contacts-results, #company-results) .people-table tbody :is(th, td) { height: 48px; padding: 6px 12px; border-bottom: 1px solid var(--soft-line); color: var(--ink); font-size: 13px; vertical-align: middle; }
#contacts-view :is(#contacts-results, #company-results) .people-table tbody tr:last-child > * { border-bottom: 0; }
#contacts-view :is(#contacts-results, #company-results) .people-table :is(th, td):first-child { padding-inline-start: 16px; }
#contacts-view :is(#contacts-results, #company-results) .people-table :is(th, td):last-child { padding-inline-end: 16px; }
#contacts-view :is(#contacts-results, #company-results) .people-table tbody tr:hover > * { background: var(--hover); }
#contacts-view #contacts-results .people-table tbody tr.is-selected > * { background: var(--accent-soft); }
#contacts-view #contacts-results .people-table :is(th, td).people-select { width: 20px; min-width: 0; padding-inline-end: 4px; }
#contacts-view #contacts-results .people-select input { display: block; margin: 0; cursor: pointer; }
#contacts-view #contacts-results .people-table .people-conversation { width: 1%; text-align: center; }
#contacts-view #contacts-results .contact-chat-button { width: 28px; min-height: 28px; margin: auto; border-radius: var(--radius-md); color: var(--muted); }
#contacts-view #contacts-results .contact-chat-button:hover { background: var(--selected); color: var(--ink); }
#contacts-view #contacts-results .contact-chat-button .icon { transform: scale(.9); }
#contacts-view .contact-cell-muted { color: var(--quiet); }
#contacts-view #contacts-results time { color: var(--muted); font-variant-numeric: tabular-nums; }
#contacts-view .people-table .contact-link { gap: 10px; max-width: 240px; color: var(--ink); font-size: 14px; font-weight: 500; }
#contacts-view .people-table .contact-link:hover span:last-child { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
#contacts-view .people-table .contact-link .avatar { --avatar-size: 28px; --avatar-font: 11px; flex: none; }
#contacts-view .contacts-empty, #contacts-view #company-results > .desk-empty { padding-block: 56px; }
#contacts-view .contacts-empty .desk-empty-icon .icon { color: var(--muted); }

/* User / Lead / Visitor type badges (contact list, profile, inbox details). */
.contact-type { display: inline-flex; align-items: center; min-height: 20px; padding: 2px 8px; border: 0; border-radius: 999px; background: var(--hover); color: var(--muted); font-size: 12px; font-weight: 500; line-height: 16px; white-space: nowrap; }
.contact-type[data-type="lead"] { background: var(--warning-soft); color: var(--warning-ink); }
.contact-type[data-type="user"] { background: var(--accent-soft); color: var(--accent); }

#contacts-view .people-pagination { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#contacts-view .people-pagination .button { min-height: 28px; padding-inline: 10px; font-size: 12px; }

/* Companies list: square company avatar + name. */
.company-avatar { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--radius-md); background: var(--hover); color: var(--muted); font-size: 12px; font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.company-avatar.large { width: 48px; height: 48px; border-radius: var(--radius-lg); font-size: 18px; }
#company-results .people-table td.company-number { font-variant-numeric: tabular-nums; }
#company-results .company-plan { display: inline-flex; }

/* ---------- Filter, rule and column popovers ---------- */
.contact-popover { padding: 8px; border: 1px solid var(--dialog-border, transparent); border-radius: var(--radius-lg); background: var(--elevated); box-shadow: var(--shadow-pop); }
.contact-popover-head { min-height: 32px; margin: 0 0 6px; padding-inline-start: 6px; }
.contact-popover-head h2 { color: var(--ink); font-size: 13px; font-weight: 600; }
.contact-popover .button { min-height: 28px; padding-inline: 10px; font-size: 12px; }
.contact-popover .button.icon-button { width: 28px; padding: 0; }
.contact-popover .search-field { height: 32px; padding-inline: 9px; }
#filter-picker-results { margin-top: 6px; }
#filter-picker-results section + section { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--soft-line); }
#filter-picker-results h3 { margin: 0; padding: 6px 8px 4px; color: var(--quiet); font-size: 12px; font-weight: 600; }
.contact-popover .filter-choice { display: flex; align-items: center; min-height: 32px; padding: 0 8px; border-radius: var(--radius-sm); color: var(--ink); font-size: 13px; }
.contact-popover .filter-choice:hover, .contact-popover .filter-choice:focus-visible { background: var(--hover); }
#contact-rule-editor .filter-operator-group legend { padding: 4px 8px 2px; color: var(--quiet); font-size: 12px; font-weight: 600; }
#contact-rule-editor .operator-choice > label { min-height: 32px; padding: 0 8px; border-radius: var(--radius-sm); color: var(--ink); font-size: 13px; font-weight: 400; gap: 8px; }
#contact-rule-editor .operator-choice > label:has(input:checked) { background: var(--selected); font-weight: 500; }
#contact-rule-editor .filter-operand { --desk-field-height: 32px; --desk-field-font-size: 13px; --desk-field-padding: 5px 9px; padding: 6px 8px 8px 32px; color: var(--muted); font-size: 12px; }
#contact-rule-editor .contact-popover-footer, .contact-popover-footer { gap: 8px; margin-top: 8px; padding: 8px 0 0; border-top-color: var(--line); }
#contact-column-options label { min-height: 32px; padding: 0 8px; border-radius: var(--radius-sm); font-size: 13px; gap: 8px; }
#contact-column-options label:has(input:disabled) { color: var(--quiet); cursor: default; }
#contact-column-options label:has(input:disabled):hover { background: transparent; }

/* ---------- Shared dialog footers in this area ---------- */
.contact-editor-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.contact-editor-footer > form { display: contents; }
.contact-editor-footer .danger-button:first-child:not(:only-child) { margin-inline-end: auto; }
:is(#contact-bulk-dialog, #contact-merge-dialog, #delete-contact-note-dialog) > .contact-editor-footer { margin-top: 20px; }
#segment-editor .segment-editor-actions { justify-content: flex-end; }
#segment-editor .segment-editor-actions #delete-contact-segment { margin-inline-end: auto; }
#segment-delete-note:not([hidden]) { padding: 10px 12px; border-radius: var(--radius-md); background: var(--danger-soft); color: var(--danger-ink); }

/* Label / value rows (profile cards, merge + erase reviews). */
.contact-fields { display: grid; gap: 0; margin: 0; }
.contact-fields > div { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr); align-items: baseline; gap: 8px; min-height: 30px; padding: 5px 0; }
.contact-fields dt { color: var(--quiet); font-size: 13px; font-weight: 400; overflow-wrap: anywhere; }
.contact-fields dd { min-width: 0; margin: 0; color: var(--ink); font-size: 13px; }
.contact-fields dd small { color: var(--quiet); font-size: 12px; }
#contact-erase-review, #contact-merge-review > .contact-fields { margin-bottom: 12px; padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--inset); }
#contact-merge-review ul { display: grid; gap: 4px; margin: 0 0 12px; padding: 0 0 0 18px; color: var(--muted); font-size: 13px; }
#contact-merge-review h3 { margin: 16px 0 6px; font-size: 14px; font-weight: 600; }
#contact-erase-dialog { width: min(520px, calc(100% - 32px)); }

/* Tags as pills. */
.contact-tag-pills { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.contact-card .contact-tag-pills { margin: -6px 0 12px; }

/* ---------- Contact profile drawer ---------- */
#contact-editor .contact-profile-head { display: flex; align-items: flex-start; gap: 14px; margin: 0 0 16px; }
#contact-editor .contact-profile-head > .avatar { --avatar-size: 48px; --avatar-font: 16px; flex: none; }
.contact-profile-identity { display: grid; gap: 4px; min-width: 0; padding-top: 2px; }
.contact-profile-name, .setup-dialog p.contact-profile-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0; color: var(--ink); font-size: 16px; line-height: 1.3; }
.contact-profile-name strong { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.setup-dialog p.contact-profile-meta, .contact-profile-meta { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.contact-profile-identity .contact-tag-pills { margin-top: 4px; }
#contact-editor .contact-profile-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--inset); }
#contact-editor .contact-profile-facts > div { min-width: 0; padding: 10px 14px; }
#contact-editor .contact-profile-facts > div + div { border-inline-start: 1px solid var(--line); }
#contact-editor .contact-profile-facts dt { color: var(--quiet); font-size: 12px; font-weight: 500; }
#contact-editor .contact-profile-facts dd { margin: 2px 0 0; color: var(--ink); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#contact-editor .contact-input-grid { gap: 12px; }
#contact-editor .desk-editor-section { margin-bottom: 16px; }
#contact-editor .contact-form-section { margin: 0; padding: 0 2px; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; }
#contact-editor .contact-form-section:last-of-type { border-bottom: 1px solid var(--line); }
#contact-editor .contact-form-section > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  list-style: none;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
#contact-editor .contact-form-section > summary::-webkit-details-marker { display: none; }
#contact-editor .contact-form-section > summary::after {
  content: '';
  width: 7px;
  height: 7px;
  margin: -3px 4px 0 auto;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 140ms ease;
}
#contact-editor .contact-form-section:not([open]) > summary::after { margin-top: 0; transform: rotate(-45deg); }
#contact-editor .contact-form-section > summary:hover { color: var(--ink); }
#contact-editor .contact-form-section > summary:hover::after { border-color: var(--ink); }
#contact-editor .contact-form-section[open] { padding-bottom: 16px; }
#contact-editor .contact-form-section #profile-note-list { margin-bottom: 10px; }
#contact-editor .profile-events .contact-section-heading { justify-content: flex-end; margin-top: -6px; }
#contact-editor .contact-profile-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
#contact-editor .contact-profile-actions .danger-button { margin-inline-start: auto; }
@media (prefers-reduced-motion: reduce) { #contact-editor .contact-form-section > summary::after { transition: none; } }

/* Notes: Intercom-style yellow note cards (drawer + inbox details). */
.contact-notes { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.contact-notes > li.contact-note { padding: 10px 12px; border: 1px solid var(--note-line); border-radius: var(--radius-md); background: var(--note-background); }
.contact-note-meta { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.contact-note-meta strong { min-width: 0; color: var(--ink); font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.contact-notes .contact-note-meta time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.contact-notes .contact-note p { margin: 4px 0 0; color: var(--ink); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.contact-notes .contact-note-delete { width: 24px; min-height: 24px; margin-inline-start: auto; padding: 0; border-radius: var(--radius-sm); color: var(--muted); }
.contact-notes .contact-note-delete:hover { background: color-mix(in srgb, var(--note-line) 55%, transparent); color: var(--ink); }
.contact-notes .contact-note-delete .icon { transform: scale(.72); }

/* Profile card in the inbox Details panel. */
.contact-card .contact-summary { align-items: flex-start; }
.contact-card .contact-summary > div { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; }
.contact-card .contact-summary strong { color: var(--ink); font-size: 14px; font-weight: 600; }
.contact-card .contact-summary p { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; }
.contact-card .contact-duplicates { margin-top: 10px; padding: 8px 10px; border: 1px solid var(--warning-soft); border-radius: var(--radius-md); background: var(--warning-soft); color: var(--warning-ink); font-size: 13px; }
.contact-card .contact-duplicates summary { font-weight: 500; cursor: pointer; }
.contact-card .contact-duplicates ul { display: grid; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.contact-card .contact-duplicates li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); }

/* ---------- Company profile drawer + linked contacts ---------- */
#company-editor .company-profile-head { display: flex; align-items: flex-start; gap: 14px; margin: 0 0 16px; }
#company-editor .company-profile-head[hidden] { display: none; }
#company-editor > #company-form { display: flex; flex-direction: column; gap: 12px; min-height: calc(100% - 72px); }
#company-editor > #company-form > .desk-editor-footer { margin-top: auto; }
#company-editor .company-avatar.large { margin-top: 2px; }
#company-editor .company-editor-fields { gap: 12px; }
#company-editor .company-contacts { margin: 16px 0 0; padding: 0; border: 0; }
#company-editor .company-contacts .contact-section-heading { margin-bottom: 8px; }
#company-editor .company-contacts h3 { margin: 0; font-size: 14px; font-weight: 600; }
#company-contact-list { display: grid; gap: 0; max-height: none; margin: 0; padding: 0; overflow: visible; border: 1px solid var(--line); border-radius: var(--radius-lg); list-style: none; }
#company-contact-list > li { display: flex; align-items: center; min-height: 44px; padding: 0 14px; }
#company-contact-list > li + li { border-top: 1px solid var(--soft-line); }
#company-contact-list > li:has(.contact-link):hover { background: var(--hover); }
#company-contact-list .contact-link { width: 100%; min-height: 40px; gap: 10px; font-size: 13px; font-weight: 500; }
#company-contact-list .contact-link:hover { color: var(--accent); }
#company-contact-list .contact-empty { color: var(--muted); font-size: 13px; }

/* Company filter dialog: one row per condition. */
#company-filter-dialog { width: min(680px, calc(100% - 32px)); }
#company-filter-rules ul { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; list-style: none; }
#company-filter-rules li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--inset); }
#company-filter-rules li + li { border-top: 1px solid var(--line); }
#company-filter-rules .contact-input-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#company-filter-rules .contact-edit-button { min-height: 36px; }
#company-filter-form #add-company-rule { justify-self: start; }
#company-filter-form > .contact-editor-footer { margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---------- Settings → People & data (inline in the settings page and as modals/drawers) ---------- */
/* Shared card for add/create forms. */
:is(#attribute-form, #contact-tag-form, #qualification-settings-form, .people-data-card):not([hidden]) {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
:is(#attribute-form, #contact-tag-form, #qualification-settings-form, .people-data-card) > :is(.contact-editor-footer, .people-data-card-footer, .dialog-actions) {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 6px -20px -20px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}
.setup-dialog .people-data-card.desk-form > fieldset:not([class]), .people-data-card > fieldset { display: grid; gap: 12px; min-width: 0; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
.setup-dialog :is(.people-data-card) > fieldset > legend { float: left; width: 100%; margin-bottom: 2px; padding: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
#attribute-form-title { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
#attribute-rename-hint:not([hidden]) { margin: -4px 0 0; color: var(--quiet); font-size: 12px; }
:is(#attribute-list, #contact-tag-list, [data-object-types], #contact-export-jobs) .desk-table-wrap { background: var(--surface); }
:is(.attribute-table, .contact-tag-table, .object-type-table, .contact-export-table) tbody th[scope="row"] { font-size: 14px; font-weight: 500; }
:is(.attribute-table, .contact-tag-table) tbody tr.is-archived th[scope="row"] { color: var(--muted); }
:is(.attribute-table, .contact-tag-table) tbody th[scope="row"] { white-space: nowrap; }
#attributes-manager:modal .attribute-table :is(th, td) { padding-inline: 8px; }
#attributes-manager:modal .attribute-table :is(th, td):first-child { padding-inline-start: 12px; }
#attributes-manager:modal .attribute-table td.attribute-row-actions .button { padding-inline: 8px; }
:is(.attribute-table, .contact-tag-table) td.attribute-row-actions { display: table-cell; width: 1%; padding-block: 0; text-align: end; white-space: nowrap; }
:is(.attribute-table, .contact-tag-table) td.attribute-row-actions .button { display: inline-flex; }
.attribute-api-id { padding: 1px 6px; border-radius: var(--radius-sm); background: var(--hover); color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.contact-tag-table .contact-tag-name { color: var(--ink); font-size: 13px; }
.object-field-pills { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.object-definitions .object-field-pills > li.badge { display: inline-flex; gap: 6px; color: var(--ink); }
.object-field-pills .badge span { color: var(--quiet); font-weight: 400; }
:is(#attribute-list, #contact-tag-list, [data-object-types]) > .desk-empty { padding: 40px 24px; border: 1px dashed var(--control-line); border-radius: var(--radius-lg); }
#attribute-list, #contact-tag-list { font-size: 13px; color: var(--muted); }
#attribute-list .desk-table span:not(.visually-hidden), #contact-tag-list .desk-table span:not(.visually-hidden) { display: inline-flex; margin: 0; font-size: 12px; }
#contact-tag-list .desk-table .contact-tag-name { font-size: 13px; }

.people-data-card-head { display: grid; gap: 2px; }
.setup-dialog .people-data-card-head h3 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
.setup-dialog .people-data-card-head p { margin: 0; color: var(--muted); font-size: 13px; }
/* In a modal the dialog is already the card: drop the inner card chrome. */
dialog:modal > :is(#qualification-settings-form, #historical-import-form, #contact-tag-form):not([hidden]) { margin-top: 12px; padding: 0; border: 0; background: transparent; }
dialog:modal > :is(#qualification-settings-form, #historical-import-form) > :is(.contact-editor-footer, .people-data-card-footer) { margin: 8px 0 0; padding: 0; border: 0; }
dialog:modal > #qualification-settings-form > .people-data-card-head h3 { display: none; }

/* Qualification fields: a checkbox list in two columns. */
#qualification-settings-dialog > p { margin: 0 0 4px; }
#qualification-settings-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; }
.setup-dialog #qualification-settings-fields label.check-field { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 0 10px; border-radius: var(--radius-md); color: var(--ink); font-size: 14px; font-weight: 400; cursor: pointer; }
.setup-dialog #qualification-settings-fields label.check-field:hover { background: var(--hover); }
.setup-dialog #qualification-settings-fields label.check-field:has(input:checked) { background: var(--selected); font-weight: 500; }
.setup-dialog #qualification-settings-fields label.check-field input { margin: 0; }
#qualify-lead-dialog { width: min(600px, calc(100% - 32px)); }
#qualification-product-companies:empty { display: none; }

/* Custom objects: field definition rows. */
.object-field-list { display: grid; gap: 8px; }
.object-field-list .object-field-definition { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 160px) auto auto; align-items: end; gap: 8px 12px; margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--inset); }
.object-field-list .object-field-definition .object-field-required { grid-column: auto; }
#custom-object-settings .object-field-definition label.object-field-required { display: flex; align-items: center; gap: 6px; min-height: 36px; font-weight: 400; white-space: nowrap; }
.object-field-definition [data-remove-object-field] { min-height: 36px; }
[data-add-object-field] { justify-self: start; }
#custom-object-settings:modal { width: min(720px, calc(100% - 32px)); }
#custom-object-records:modal { width: min(620px, calc(100% - 32px)); }
.custom-object-list { display: grid; gap: 8px; }
.custom-object-list > .contact-empty { padding: 16px; border: 1px dashed var(--control-line); border-radius: var(--radius-lg); color: var(--muted); font-size: 13px; text-align: center; }
.custom-object-card { margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.custom-object-card h4 { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
.custom-object-card > p { margin: 2px 0 8px; color: var(--muted); font-size: 12px; }
.custom-object-card dl { display: grid; gap: 2px; margin: 0; }
.custom-object-card dl div { grid-template-columns: minmax(0, 40%) minmax(0, 1fr); gap: 8px; padding: 3px 0; font-size: 13px; }
.custom-object-card dt { color: var(--quiet); }
.custom-object-card dd { margin: 0; color: var(--ink); }
.custom-object-card > .button { margin-top: 8px; min-height: 28px; padding-inline: 10px; font-size: 12px; }
#custom-object-records [data-record-more]:not([hidden]) { justify-self: start; margin-top: 8px; }

/* Imports: dropzone, stepper, column mapping. */
.import-dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 24px 20px 18px;
  border: 1.5px dashed var(--control-line);
  border-radius: var(--radius-lg);
  background: var(--inset);
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.import-dropzone:hover, .import-dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.import-dropzone-icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 6px; border-radius: 50%; background: var(--surface); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.import-dropzone-title { color: var(--ink); font-size: 14px; font-weight: 600; }
.import-dropzone-hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.setup-dialog .import-dropzone > input[type="file"] { width: auto; max-width: 100%; min-height: 0; margin-top: 10px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.import-dropzone > input[type="file"]::file-selector-button {
  height: 32px;
  margin-inline-end: 10px;
  padding: 0 12px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.import-dropzone > input[type="file"]::file-selector-button:hover { background: var(--hover); }
.import-dropzone > input[type="file"]:disabled { cursor: default; }

.import-steps { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; padding: 0; list-style: none; counter-reset: none; }
.import-step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; white-space: nowrap; }
.import-step + .import-step::before { content: ''; width: 24px; height: 1px; margin-inline-end: 0; background: var(--control-line); }
.import-step-mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--control-line); border-radius: 50%; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
/* Step state follows the dialog's content: no columns yet → upload; columns mapped → map; result shown → review. */
.contact-import-dialog .import-step[data-import-step="upload"],
.contact-import-dialog:has(#contact-import-columns:not(:empty)) .import-step[data-import-step="map"],
.contact-import-dialog:has(#contact-import-result:not([hidden])) .import-step[data-import-step="review"] { color: var(--ink); }
.contact-import-dialog .import-step[data-import-step="upload"] .import-step-mark,
.contact-import-dialog:has(#contact-import-columns:not(:empty)) .import-step[data-import-step="map"] .import-step-mark,
.contact-import-dialog:has(#contact-import-result:not([hidden])) .import-step[data-import-step="review"] .import-step-mark { border-color: var(--primary-fill); background: var(--primary-fill); color: var(--primary-text); }
.contact-import-dialog:has(#contact-import-columns:not(:empty)) .import-step[data-import-step="upload"] .import-step-mark,
.contact-import-dialog:has(#contact-import-result:not([hidden])) .import-step[data-import-step="map"] .import-step-mark { border-color: var(--success-ink); background: var(--success-soft); color: var(--success-ink); }
.contact-import-dialog:modal { width: min(640px, calc(100% - 32px)); }
.contact-import-dialog .import-role { max-width: 260px; }
.import-map-head { display: none; grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr); gap: 10px; padding: 0 12px; color: var(--muted); font-size: 12px; font-weight: 500; }
.import-map-head:has(+ #contact-import-columns:not(:empty)) { display: grid; margin-bottom: -6px; }
.import-map-head span:last-child { grid-column: 3; }
.import-map:not(:empty) { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); }
.setup-dialog .import-map > label.import-map-row { display: grid; grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; font-weight: 400; }
.import-map > label.import-map-row + label.import-map-row { border-top: 1px solid var(--soft-line); }
.import-map-source { display: grid; min-width: 0; }
.import-map-source strong { overflow: hidden; color: var(--ink); font-size: 13px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.import-map-source small { overflow: hidden; color: var(--quiet); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.import-map-arrow { color: var(--quiet); text-align: center; }
.import-map select { --desk-field-height: 32px; font-size: 13px; }
#contact-import-result:not([hidden]) { margin: 16px 0 0; padding: 10px 12px; border-radius: var(--radius-md); background: var(--success-soft); color: var(--success-ink); font-size: 13px; font-weight: 500; }
#contact-import-error-rows { margin-top: 10px; font-size: 13px; }
#contact-import-error-rows summary { color: var(--danger-ink); font-weight: 500; cursor: pointer; }
#contact-import-failures { display: grid; gap: 4px; margin: 8px 0 0; padding: 0 0 0 18px; color: var(--muted); }

/* Historical import. */
.historical-import-format { border: 1px solid var(--line); border-radius: var(--radius-md); }
.historical-import-format > summary { display: flex; align-items: center; min-height: 40px; padding: 0 12px; color: var(--ink); font-size: 13px; font-weight: 500; cursor: pointer; }
.historical-import-format > summary { list-style: none; }
.historical-import-format > summary::-webkit-details-marker { display: none; }
.historical-import-format > summary::after { content: ''; width: 7px; height: 7px; margin: -2px 2px 0 auto; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform 140ms ease; }
.historical-import-format[open] > summary::after { margin-top: -4px; transform: rotate(45deg); }
.setup-dialog .historical-import-format pre { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-md) var(--radius-md); font-size: 12px; }
.historical-import-result:not(:empty) { margin-top: 16px; color: var(--muted); font-size: 13px; }
.historical-import-result ul { display: grid; gap: 0; margin: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); list-style: none; }
.historical-import-result li { padding: 10px 14px; color: var(--ink); font-variant-numeric: tabular-nums; }
.historical-import-result li + li { border-top: 1px solid var(--soft-line); }

/* Contact exports: start form + history table. */
.contact-export-dialog:modal { width: min(760px, calc(100% - 32px)); }
.contact-export-form { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.contact-export-form label { max-width: 320px; }
.setup-dialog .contact-export-heading { margin: 20px 0 10px; color: var(--ink); font-size: 14px; font-weight: 600; }
.contact-export-status:not([hidden]) { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent); font-size: 13px; }
.contact-export-table th[scope="row"] { min-width: 180px; }
.contact-export-name { display: block; color: var(--ink); font-weight: 500; }
.contact-export-table small { display: block; max-width: 340px; margin-top: 2px; overflow: hidden; color: var(--quiet); font-size: 12px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.contact-export-table small.contact-export-failure { color: var(--danger-ink); white-space: normal; }
.contact-export-table time, .contact-export-count { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.contact-export-table td.contact-export-download { width: 1%; text-align: end; white-space: nowrap; }
#contact-export-jobs > .desk-empty { padding: 36px 24px; border: 1px dashed var(--control-line); border-radius: var(--radius-lg); }

/* Contact tags modal + attributes drawer sizing. */
#contact-tags-dialog:modal { width: min(640px, calc(100% - 32px)); }
#contact-tag-form:not([hidden]) { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
#contact-tag-form > .contact-editor-footer { margin: 0; padding: 0; border: 0; }

/* Inline settings pages: the dialog body becomes the page (tables and cards on the page background). */
#workspace-settings-editor > :is(#attributes-manager, #contact-tags-dialog, #custom-object-settings, #contact-export-dialog, #historical-import-dialog, #qualification-settings-dialog)[open] {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
#workspace-settings-editor > :is(#attributes-manager, #contact-tags-dialog, #custom-object-settings, #contact-export-dialog)[open] { max-width: 880px; }
#workspace-settings-editor > :is(#historical-import-dialog, #qualification-settings-dialog)[open] { max-width: 760px; }
#workspace-settings-editor > #qualification-settings-dialog[open] > #qualification-settings-form { margin-top: 0; }
#workspace-settings-editor > #historical-import-dialog[open] > #historical-import-form { margin-top: 0; }
#workspace-settings-editor > #contact-export-dialog[open] > .contact-export-heading { margin-top: 0; }
#workspace-settings-editor > #contact-export-dialog[open] > .contact-export-form:not([hidden]) { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
#workspace-settings-editor > :is(#attributes-manager, #contact-tags-dialog, #custom-object-settings)[open] > form { max-width: none; }
#workspace-settings-editor > dialog > :is(#attribute-form, #contact-tag-form, [data-object-type]) { margin-top: 16px; }

/* ---------- Narrow widths ---------- */
@media (max-width: 1000px) {
  #contacts-view .people-results-actions .search-field { flex-basis: 180px; width: 180px; }
}
@media (max-width: 760px) {
  #contacts-view .segments-sidebar { flex-direction: row; align-items: center; overflow: auto; }
  #contacts-view .segments-sidebar > h2 { display: none; }
  #contacts-view #segment-list { display: flex; gap: 4px; }
  #contacts-view #segment-list :is(.segment-group-heading, .segment-empty) { display: none; }
  #contacts-view .segments-sidebar .segment-link { flex: none; width: auto; white-space: nowrap; }
  #contacts-view .people-filter-bar { flex-direction: column; }
  #contacts-view .people-results-actions { justify-content: flex-start; }
  #contact-editor .contact-profile-facts { grid-template-columns: minmax(0, 1fr); }
  #contact-editor .contact-profile-facts > div + div { border-inline-start: 0; border-top: 1px solid var(--line); }
  #company-filter-rules .contact-input-grid, .object-field-list .object-field-definition { grid-template-columns: minmax(0, 1fr); }
}
