/* CRM screens: contacts, properties, notes, leads. Builds on the shared classes in app.css. */

/* People | Properties switch */
.crm-seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 12px;
  background: #e8ecf1; border-radius: var(--radius-sm);
}
.crm-seg-item {
  display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 6px;
  color: var(--muted); font-weight: 600; text-decoration: none;
}
.crm-seg-item.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Filter chips: one horizontally scrolling row */
.crm-filters {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 0 12px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.crm-filters::-webkit-scrollbar { display: none; }
.crm-filter {
  flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text); font-size: 0.9rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.crm-filter.active { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.crm-filter-tag { font-weight: 500; }
.crm-filter-sep { flex: 0 0 1px; background: var(--border); margin: 6px 2px; }

/* Initials avatar */
.crm-avatar {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--brand) 14%, #fff); color: var(--brand);
  font-weight: 700; font-size: 0.9rem; letter-spacing: 0.02em;
}
.crm-avatar-lg { flex-basis: 56px; width: 56px; height: 56px; font-size: 1.15rem; }

/* Detail headers */
.crm-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.crm-head-text { min-width: 0; }
.crm-head-text h1 { overflow-wrap: anywhere; }
.page-header > .btn, .page-header > [data-share] { flex: 0 0 auto; }
.crm-break { overflow-wrap: anywhere; }

.crm-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.crm-tag { text-decoration: none; font-weight: 600; }

.crm-actions { display: flex; gap: 8px; margin-bottom: 20px; }
.crm-actions > .btn { flex: 1 1 0; min-width: 0; padding-left: 8px; padding-right: 8px; }

/* Pill radios laid out as an even grid (use with .pills). --cols sets the column count. */
.crm-pill-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
.crm-pill-grid label { justify-content: center; text-align: center; padding-left: 8px; padding-right: 8px; }
.crm-primary-action { margin-bottom: 8px; }

.crm-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.crm-section-head .section-title { margin: 0; }
.crm-section-head .btn { margin-right: -8px; }

.crm-row-chips { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

/* Notes and timeline */
.crm-note-form { display: grid; gap: 8px; }
.crm-note-form textarea { min-height: 72px; }

.crm-timeline { list-style: none; margin: 4px 0 0; padding: 0 0 0 4px; }
.crm-tl-item { position: relative; display: flex; gap: 12px; padding-bottom: 16px; }
.crm-tl-item::before {
  content: ""; position: absolute; left: 5px; top: 16px; bottom: 0; width: 2px; background: var(--border);
}
.crm-tl-item:last-child::before { display: none; }
.crm-tl-dot {
  flex: 0 0 12px; width: 12px; height: 12px; margin-top: 4px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 3px var(--bg);
}
.crm-tl-inspection .crm-tl-dot { background: var(--brand); }
.crm-tl-delivery .crm-tl-dot { background: var(--ok); }
.crm-tl-failed .crm-tl-dot { background: var(--danger); }
.crm-tl-body { min-width: 0; flex: 1; }
.crm-tl-kind { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.crm-tl-title { display: block; font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.crm-tl-title { color: var(--brand); min-height: 24px; }
.crm-tl-text { font-weight: 400; white-space: normal; }
.crm-tl-meta { color: var(--muted); font-size: 0.85rem; }

/* New property: homeowner block. The chosen mode shows its fields (pure CSS, no JS needed). */
.crm-owner .crm-owner-modes { --cols: 3; margin-bottom: 14px; }
.crm-owner-new, .crm-owner-existing { display: none; }
.crm-owner:has(input[name=owner_mode][value=new]:checked) .crm-owner-new { display: block; }
.crm-owner:has(input[name=owner_mode][value=existing]:checked) .crm-owner-existing { display: block; }

/* Search-and-pick widget (see crm.js) */
.crm-picker-results:not(:empty) { margin-top: 8px; }
.crm-picker .crm-picker-chosen { display: none; }
.crm-picker.is-picked .crm-picker-search { display: none; }
.crm-picker.is-picked .crm-picker-chosen {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 60px;
  border: 1px solid var(--brand); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--brand) 6%, #fff);
}
.crm-pick-list { margin-bottom: 0; }
.crm-pick-row {
  width: 100%; background: var(--surface); border: 0; border-bottom: 1px solid var(--border);
  font: inherit; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.crm-pick-row .row-title, .crm-pick-row .row-sub { display: block; }
.crm-pick-row:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.crm-pick-empty { padding: 8px 2px; }

/* Leads */
.crm-lead { align-items: flex-start; }
.crm-lead::after { align-self: center; }
.crm-lead-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
