/* CRM — People list, filter builder, person detail.
 *
 * Everything here is namespaced .crm-* so it cannot collide with the 133 KB
 * styles.css. Two house rules observed deliberately:
 *   1. .muted / .form-label / .banner / .btn-ghost / .btn-outline are used all
 *      over the portal but are NEVER DEFINED — they render as UA defaults. We
 *      define our own .crm-muted / .crm-ghost instead of inheriting that bug.
 *   2. The global `input` rule stretches checkboxes and radios; styles.css
 *      already carries the reset, so we never re-fix it inline.
 */

.crm-wrap {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 0;
  height: calc(100vh - 118px);
  min-height: 460px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card-bg, #fff);
}
.crm-wrap.crm-filters-open { grid-template-columns: 248px minmax(0, 1fr) 372px; }

.crm-muted { color: var(--text-secondary, #6b7280); }
.crm-small { font-size: 12px; }

/* ---------- left rail ---------- */
.crm-rail {
  border-right: 1px solid var(--border, #e5e7eb);
  background: var(--bg-subtle, #fafafa);
  overflow-y: auto;
  padding: 10px 0 24px;
}
.crm-rail-head {
  padding: 4px 14px 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.crm-rail-title { font-weight: 700; font-size: 13px; letter-spacing: .02em; }
.crm-rail-search { padding: 0 10px 10px; }
.crm-rail-search input {
  width: 100%; font-size: 13px; padding: 6px 9px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 7px;
  background: var(--card-bg, #fff);
}
.crm-folder {
  padding: 11px 14px 5px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-secondary, #6b7280);
}
.crm-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px; font-size: 13px; cursor: pointer;
  border-left: 3px solid transparent; line-height: 1.3;
}
.crm-list-item:hover { background: var(--bg-hover, #f1f5f9); }
.crm-list-item.active {
  background: var(--bg-hover, #eef2ff);
  border-left-color: var(--accent, #4f46e5);
  font-weight: 600;
}
.crm-list-name { flex: 1; min-width: 0; overflow: hidden;
                 text-overflow: ellipsis; white-space: nowrap; }
.crm-list-count {
  font-size: 11px; color: var(--text-secondary, #6b7280);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}

/* ---------- centre ---------- */
.crm-main { display: flex; flex-direction: column; min-width: 0; }
.crm-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border, #e5e7eb);
  flex-wrap: wrap;
}
.crm-bar-title { font-weight: 700; font-size: 15px; }
.crm-bar-spacer { flex: 1; }
.crm-count-chip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-hover, #f1f5f9); font-variant-numeric: tabular-nums;
}
.crm-ghost {
  background: transparent; border: 1px solid var(--border, #e5e7eb);
  border-radius: 7px; padding: 5px 11px; font-size: 13px; cursor: pointer;
  color: inherit;
}
.crm-ghost:hover { background: var(--bg-hover, #f1f5f9); }
.crm-ghost.on { background: var(--accent, #4f46e5); color: #fff;
                border-color: var(--accent, #4f46e5); }

/* The plain-English read-back. This is the bit that makes a nested boolean
   legible to someone who does not think in booleans. */
.crm-sentence {
  padding: 9px 14px; font-size: 13px; line-height: 1.5;
  background: var(--bg-subtle, #fafafa);
  border-bottom: 1px solid var(--border, #e5e7eb);
  color: var(--text-secondary, #4b5563);
}
.crm-sentence b { color: var(--text, #111827); font-weight: 600; }

/* param chips — what collapses the TOTAL/Active/Staged sublist axis */
.crm-chips { display: flex; gap: 6px; align-items: center;
             padding: 8px 14px; flex-wrap: wrap;
             border-bottom: 1px solid var(--border, #e5e7eb); }
.crm-chip {
  font-size: 12px; padding: 4px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border, #e5e7eb); background: var(--card-bg, #fff);
}
.crm-chip.on { background: var(--accent, #4f46e5); color: #fff;
               border-color: var(--accent, #4f46e5); }

/* ---------- virtualized table ---------- */
.crm-scroll { flex: 1; overflow: auto; position: relative; }
.crm-table { width: 100%; border-collapse: separate; border-spacing: 0;
             font-size: 13px; table-layout: fixed; }
.crm-table thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--card-bg, #fff);
  border-bottom: 1px solid var(--border, #e5e7eb);
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-secondary, #6b7280);
  padding: 8px 10px; white-space: nowrap; cursor: pointer; user-select: none;
}
.crm-table td {
  padding: 0 10px; height: 44px;              /* fixed row height: the whole
                                                 virtualization scheme rests
                                                 on this being constant */
  border-bottom: 1px solid var(--border-light, #f1f5f9);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crm-table tbody tr:hover { background: var(--bg-hover, #f8fafc); }
.crm-name { font-weight: 600; }
.crm-sub { font-size: 11px; color: var(--text-secondary, #6b7280); }
.crm-num { text-align: right; font-variant-numeric: tabular-nums; }
.crm-spacer td { padding: 0; height: 0; border: none; }
.crm-pill {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  border-radius: 999px; background: var(--bg-hover, #f1f5f9);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- filter panel ---------- */
.crm-filters {
  border-left: 1px solid var(--border, #e5e7eb);
  background: var(--bg-subtle, #fafafa);
  overflow-y: auto; padding: 12px;
}
.crm-fgroup {
  border: 1px solid var(--border, #e5e7eb); border-radius: 9px;
  background: var(--card-bg, #fff); padding: 8px; margin-bottom: 9px;
}
.crm-fgroup.depth-1 { border-left: 3px solid var(--accent, #4f46e5); }
.crm-fgroup.depth-2 { border-left: 3px solid #0d9488; }
.crm-fgroup.depth-3 { border-left: 3px solid #9333ea; }
.crm-fgroup-head {
  display: flex; align-items: center; gap: 7px; margin-bottom: 7px;
}
.crm-op-toggle {
  font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 6px;
  border: 1px solid var(--border, #e5e7eb); cursor: pointer;
  background: var(--card-bg, #fff);
}
.crm-op-toggle.or { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.crm-op-toggle.and { background: #e0e7ff; border-color: #c7d2fe; color: #3730a3; }
.crm-cond {
  display: grid; grid-template-columns: 1fr auto; gap: 6px;
  align-items: start; padding: 6px; border-radius: 7px;
  margin-bottom: 5px; background: var(--bg-subtle, #fafafa);
}
.crm-cond select, .crm-cond input {
  width: 100%; font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  background: var(--card-bg, #fff); margin-bottom: 4px;
}
.crm-cond-x {
  background: none; border: none; cursor: pointer; font-size: 15px;
  color: var(--text-secondary, #9ca3af); line-height: 1; padding: 2px 4px;
}
.crm-cond-x:hover { color: var(--danger, #dc2626); }
.crm-multi {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px;
}
.crm-multi .crm-tagx {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent, #4f46e5); color: #fff; cursor: pointer;
}
.crm-empty { padding: 40px 20px; text-align: center;
             color: var(--text-secondary, #6b7280); font-size: 14px; }

@media (max-width: 1100px) {
  .crm-wrap, .crm-wrap.crm-filters-open { grid-template-columns: 1fr; height: auto; }
  .crm-rail { display: none; }
  .crm-filters { border-left: none; border-top: 1px solid var(--border, #e5e7eb); }
}

/* ---------- person detail page ---------- */
.crm-back {
  display: inline-block; font-size: 12px; margin-bottom: 4px;
  color: var(--text-secondary, #6b7280); text-decoration: none;
}
.crm-back:hover { color: var(--accent, #4f46e5); }

.crm-person {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: start;
}
.crm-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.crm-pcard { padding: 0; overflow: hidden; }
.crm-pcard-body { padding: 10px 14px 14px; font-size: 13px; }
.crm-psummary {
  cursor: pointer; font-size: 12px; font-weight: 600; padding: 10px 14px;
  color: var(--text-secondary, #4b5563); list-style: revert;
}
.crm-prow {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 4px 0; border-bottom: 1px solid var(--border-light, #f1f5f9);
  align-items: baseline;
}
.crm-prow:last-child { border-bottom: none; }
.crm-prow > span:last-child { text-align: right; min-width: 0; word-break: break-word; }

.crm-statgrid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;
}
.crm-statgrid > div {
  background: var(--bg-subtle, #fafafa); border-radius: 8px; padding: 8px;
  text-align: center;
}
.crm-statgrid b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.crm-statgrid span { font-size: 11px; color: var(--text-secondary, #6b7280); }

.crm-event {
  border-left: 2px solid var(--border, #e5e7eb);
  padding: 8px 0 12px 12px; margin-left: 4px;
}
.crm-event-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.crm-summary {
  margin: 6px 0; padding: 7px 9px; border-radius: 7px; font-size: 12.5px;
  background: var(--bg-subtle, #f8fafc); line-height: 1.45;
}
.crm-event audio { width: 100%; max-width: 360px; height: 32px; margin: 6px 0; }
.crm-transcript {
  font-size: 12px; line-height: 1.5; white-space: pre-wrap;
  max-height: 320px; overflow-y: auto; padding: 8px;
  background: var(--bg-subtle, #fafafa); border-radius: 7px;
}

@media (max-width: 1100px) {
  .crm-person { grid-template-columns: 1fr; }
}

/* ---------- next-steps brief ---------- */
.crm-brief { border-top: 3px solid var(--border, #e5e7eb); }
.crm-brief-high   { border-top-color: #dc2626; }
.crm-brief-medium { border-top-color: #d97706; }
.crm-brief-low    { border-top-color: #9ca3af; }
.crm-urg {
  font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: var(--bg-hover, #f1f5f9); color: var(--text-secondary, #6b7280);
}
.crm-urg-high   { background: #fee2e2; color: #991b1b; }
.crm-urg-medium { background: #fef3c7; color: #92400e; }
.crm-brief-head { font-size: 14px; font-weight: 600; line-height: 1.4; margin-bottom: 10px; }
.crm-action { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 9px; }
.crm-action-n {
  flex: 0 0 20px; height: 20px; border-radius: 50%; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent, #4f46e5); color: #fff; font-weight: 700;
}
.crm-action-do { font-weight: 600; line-height: 1.4; }
.crm-action-why { font-size: 12px; color: var(--text-secondary, #6b7280); line-height: 1.45; }
.crm-brief-sub {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-secondary, #6b7280);
  margin: 12px 0 4px;
}
.crm-brief-sub.crm-warn { color: #b45309; }
.crm-brief-list { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.5; }
.crm-brief-list.crm-warn { color: #92400e; }
.crm-brief-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 12px; padding-top: 9px;
  border-top: 1px solid var(--border-light, #f1f5f9);
}

/* ---------- call bar ---------- */
/* Fixed to the viewport and appended to <body>, so it survives navigating
   between the list and a contact while a call is live. */
.crm-callbar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 9000; display: flex; align-items: center; gap: 14px;
  background: #111827; color: #f9fafb; padding: 11px 16px;
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  min-width: 380px; max-width: calc(100vw - 32px); flex-wrap: wrap;
}
.crm-cb-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.crm-cb-ring { background: #f59e0b; animation: crm-pulse 1s infinite; }
.crm-cb-live { background: #10b981; }
.crm-cb-done { background: #6b7280; }
@keyframes crm-pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.crm-cb-who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.crm-cb-who b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-cb-sub { font-size: 11.5px; color: #9ca3af; font-variant-numeric: tabular-nums; }
.crm-cb-actions { display: flex; gap: 7px; }
.crm-cb-btn {
  background: #374151; color: #f9fafb; border: none; border-radius: 7px;
  padding: 6px 13px; font-size: 12.5px; cursor: pointer;
}
.crm-cb-btn:hover { background: #4b5563; }
.crm-cb-btn.on { background: #b45309; }
.crm-cb-end { background: #dc2626; }
.crm-cb-end:hover { background: #b91c1c; }
.crm-cb-outcomes { display: flex; gap: 6px; flex-wrap: wrap; }
.crm-cb-out {
  background: #1f2937; color: #f9fafb; border: 1px solid #374151;
  border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer;
}
.crm-cb-out:hover { background: #4f46e5; border-color: #4f46e5; }

/* ---------- inline editors on the record ---------- */
.crm-editrow { display: flex; gap: 6px; align-items: center; }
.crm-editrow select, .crm-editrow input {
  font-size: 12px; padding: 4px 7px; border-radius: 6px;
  border: 1px solid var(--border, #e5e7eb); background: var(--card-bg, #fff);
  max-width: 100%;
}
.crm-actbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.crm-callbtn {
  background: var(--accent, #4f46e5); color: #fff; border: none;
  border-radius: 7px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.crm-callbtn:hover { filter: brightness(1.08); }
.crm-rowcall {
  background: none; border: none; cursor: pointer; padding: 2px 5px;
  border-radius: 5px; font-size: 13px; color: var(--accent, #4f46e5);
}
.crm-rowcall:hover { background: var(--bg-hover, #eef2ff); }
