:root {
  --border: oklch(90% 0.01 90);
  --bg: oklch(98% 0.008 90);
  --bg-panel: oklch(99% 0.004 90);
  --text: oklch(24% 0.012 90);
  --text-muted: oklch(52% 0.01 90);
  --accent: oklch(38% 0.06 155);
  --accent-tint: oklch(93% 0.025 155);
  --accent-text: oklch(32% 0.08 155);
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Public Sans', -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.brand-block { display: flex; align-items: baseline; gap: 10px; }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 600; color: var(--accent-text); text-decoration: none; }
.brand-tagline { font-size: 12.5px; color: var(--text-muted); }

.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar nav a { color: var(--accent-text); text-decoration: none; font-size: 0.9em; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

main { padding: 0; }

.empty { color: #999; font-style: italic; }

.lead-form .field-hint { margin: -6px 0 0 0; font-size: 12px; color: var(--text-muted); }

.lead-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
  padding: 24px;
}

.screenshot-upload {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
  background: var(--bg);
}
.screenshot-upload:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.screenshot-upload-hint { margin: 0; font-size: 13px; color: var(--text-muted); }
.screenshot-upload-hint button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-text);
  text-decoration: underline;
  font: inherit;
  font-size: inherit;
  cursor: pointer;
}
.kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
  background: var(--bg);
  color: var(--text-muted);
}

.screenshot-upload-status { margin: 8px 0 0 0; font-size: 12.5px; }
.screenshot-upload-status.is-success { color: #2f8a4e; }
.screenshot-upload-status.is-error { color: #b3441e; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9em; }
label.checkbox { flex-direction: row; align-items: center; gap: 6px; }

/* compact single-row "add activity" form, pill-styled to match the
   read-only pills/chips used everywhere else in the detail pane */
.activity-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--bg-panel);
}
.activity-date { border-radius: 8px; padding: 7px 10px; }
.method-toggles { display: flex; gap: 6px; border: none; padding: 0; margin: 0; }
.method-toggle {
  flex-direction: row;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}
.method-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.method-toggle:has(input:checked) { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.activity-note { flex: 1; min-width: 200px; border-radius: 8px; padding: 7px 10px; }

input, select, textarea, button {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  padding: 8px 14px;
}

.btn-primary {
  background: var(--accent);
  color: white !important;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  text-decoration: none !important;
}
.btn-primary:hover { filter: brightness(1.08); }

/* ---- two-pane split view (board + lead detail) ---- */

.split-view {
  display: flex;
  height: calc(100vh - 64px);
}
.dev-banner ~ main .split-view { height: calc(100vh - 64px - 30px); }

.list-pane {
  width: 50%;
  min-width: 380px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
}

.list-pane-controls { padding: 16px 20px 12px 20px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }

.search-form { margin: 0; }
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  color: var(--text-muted);
  max-width: 340px;
}
.search-box input { flex: 1; border: none; padding: 0; background: transparent; }
.search-box input:focus { outline: none; }

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}
.chip-active { background: var(--accent); color: white; border-color: var(--accent); }

.sort-pills { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.sort-label { font-size: 12px; color: var(--text-muted); margin-right: 2px; }

.hide-closed-toggle {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  cursor: pointer;
  user-select: none;
}
.hide-closed-toggle input { margin: 0; }

.lead-rows { flex: 1; overflow-y: auto; }

.lead-row { padding: 12px 20px; border-bottom: 1px solid var(--border); cursor: pointer; }
.lead-row:hover { background: oklch(96% 0.008 90); }
.lead-row-selected { background: var(--accent-tint); box-shadow: inset 3px 0 0 var(--accent); }
.lead-row-selected:hover { background: var(--accent-tint); }

.lead-row-top { display: flex; align-items: center; gap: 8px; }
.lead-row-name { font-weight: 600; font-size: 14.5px; color: inherit; text-decoration: none; flex-shrink: 0; }
.lead-row-name:hover { text-decoration: underline; }

.row-auto-added, .row-duplicate-flag { font-size: 12px; flex-shrink: 0; cursor: default; opacity: 0.85; }

.row-tags { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; min-width: 20px; }
.row-tag {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.row-status-form { margin: 0 0 0 auto; flex-shrink: 0; }
.row-status-form .status-pill-select { font-size: 10.5px; padding: 3px 24px 3px 10px; }

.lead-row-contact { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 6px; }
.lead-row-contact-items { display: flex; gap: 18px; flex-wrap: wrap; }
.lead-row-contact-right { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
.lead-row-clinician { font-size: 11px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* Same [hidden]-defeating mistake as the inner icons below, just one
   level up — the outer wrapper carries the actual Closed-Won gate
   (list_pane.html's {% if lead.status != "Closed Won" %}hidden{% endif %}),
   so this one being unconditional was what made the whole widget show
   on every status regardless of the gate. */
.row-add-contact:not([hidden]) { display: inline-flex; }
.row-add-contact { align-items: center; }
.row-add-contact .add-contact-trigger,
.row-add-contact .add-contact-done {
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
/* explicit display only on the visible state — an element also needs
   to still fall back to the browser's own [hidden]{display:none} when
   toggled off, which author CSS setting `display` unconditionally
   would silently defeat regardless of selector specificity (a plain
   `.foo{display:x}` always wins over the UA stylesheet's [hidden]
   rule, no matter how it's written) */
.row-add-contact .add-contact-trigger:not([hidden]) { display: inline-flex; }
.row-add-contact .add-contact-done:not([hidden]) { display: inline-flex; }
.row-add-contact .add-contact-trigger {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
}
.row-add-contact .add-contact-trigger:hover { border-color: var(--accent); color: var(--accent-text); }
.row-add-contact .add-contact-done { color: #2f8a4e; }
.contact-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text); }
.contact-item svg { color: var(--text-muted); flex-shrink: 0; }

.copy-text {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  text-decoration: underline dotted 1px var(--border);
  text-underline-offset: 2px;
  border-radius: 3px;
}
.copy-text:hover { color: var(--accent-text); }
.copy-text.copy-flash { background: var(--accent-tint); color: var(--accent-text); text-decoration: none; }

.icon-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  padding: 0 2px;
  opacity: 0.55;
  text-decoration: none;
}
.icon-link:hover { opacity: 1; color: var(--accent-text); }

.lead-row-bottom { display: flex; justify-content: space-between; margin-top: 5px; font-size: 12px; color: var(--text-muted); }

/* status pills, shared by list rows and the detail header — filter
   chips (.chip.status-XXX) reuse the exact same palette so a chip
   reads as "this status" at a glance, same as the pill/select do */
.status-pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.status-pill.status-new, .chip.status-new { background: oklch(94% 0.02 240); color: oklch(38% 0.04 240); }
.status-pill.status-awaiting, .chip.status-awaiting { background: oklch(93% 0.04 75); color: oklch(42% 0.09 75); }
.status-pill.status-scheduled, .chip.status-scheduled { background: oklch(90% 0.05 155); color: oklch(32% 0.08 155); }
.status-pill.status-won, .chip.status-won { background: oklch(90% 0.05 155); color: oklch(32% 0.08 155); }
.status-pill.status-lost, .chip.status-lost { background: oklch(93% 0.03 20); color: oklch(42% 0.08 20); }
.status-pill.status-noresponse, .chip.status-noresponse { background: oklch(92% 0.01 60); color: oklch(45% 0.02 60); }
.status-pill.status-other, .chip.status-other { background: oklch(93% 0.025 300); color: oklch(42% 0.06 300); }

.chip[class*="status-"] { border-color: transparent; }
.chip[class*="status-"].chip-active { box-shadow: inset 0 0 0 1.5px currentColor; font-weight: 600; }

.lead-row.status-won, .lead-row.status-lost, .lead-row.status-noresponse { opacity: 0.7; }

.stale-flag { font-size: 0.78em; font-weight: 600; color: #8a4a00; margin-bottom: 6px; }
.lead-row-stale { border-left: 3px solid #b45f06; }

.stale-banner {
  background: #fdf2e3;
  border: 1px solid #b45f06;
  color: #8a4a00;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 16px;
}

.pending-intake-banner {
  background: #e8f0fd;
  border: 1px solid #3167c9;
  color: #1d4a99;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 16px;
}

.pending-intake-panel {
  border-color: #3167c9;
  margin-bottom: 16px;
  text-align: left;
}

.duplicate-banner {
  background: #fdf2e3;
  border: 1px solid #b45f06;
  color: #8a4a00;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.9em;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.duplicate-banner a { color: inherit; text-decoration: underline; }
.duplicate-banner form { flex-shrink: 0; }

/* ---- detail pane ---- */

.detail-pane { flex: 1; overflow-y: auto; padding: 28px 40px 40px 40px; }
.detail-pane-empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-style: italic; }

.detail-header-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-header-top h1 { font-family: var(--serif); font-size: 28px; font-weight: 600; margin: 0; }
.detail-subtitle { font-size: 13.5px; color: var(--text-muted); margin-top: 6px; }

.status-pill-form { display: flex; align-items: center; gap: 8px; margin: 0; }

.status-pill-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: 999px;
  padding: 5px 28px 5px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2332264d' stroke-width='3'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
/* reuse the same per-status colors as the read-only pills */
.status-pill-select.status-new { background-color: oklch(94% 0.02 240); color: oklch(38% 0.04 240); }
.status-pill-select.status-awaiting { background-color: oklch(93% 0.04 75); color: oklch(42% 0.09 75); }
.status-pill-select.status-scheduled { background-color: oklch(90% 0.05 155); color: oklch(32% 0.08 155); }
.status-pill-select.status-won { background-color: oklch(90% 0.05 155); color: oklch(32% 0.08 155); }
.status-pill-select.status-lost { background-color: oklch(93% 0.03 20); color: oklch(42% 0.08 20); }
.status-pill-select.status-noresponse { background-color: oklch(92% 0.01 60); color: oklch(45% 0.02 60); }
.status-pill-select.status-other { background-color: oklch(93% 0.025 300); color: oklch(42% 0.06 300); }
/* closed-lost-reason select has no status- class; keep it plain/neutral */
#closed-lost-reason { background-color: var(--bg); color: var(--text); border: 1px solid var(--border); }

.btn-ghost {
  display: inline-block;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-text); }

.duplicate-banner-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.reconcile-view { max-width: 900px; margin: 0 auto; padding: 28px 40px; }
.reconcile-columns { display: flex; gap: 24px; margin: 20px 0; }
.reconcile-column {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  background: var(--bg);
}
.reconcile-column h2 { margin: 0 0 12px 0; font-size: 1.1em; }
.reconcile-fields { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 16px 0; }
.reconcile-fields dt { font-size: 0.8em; color: var(--text-muted); }
.reconcile-fields dd { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.contact-cards { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-top: 24px; }
.contact-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--bg-panel); }
.contact-card-label { display: flex; align-items: center; gap: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.contact-card-value { font-size: 14px; font-weight: 600; margin-top: 6px; }
.contact-card-actions { display: flex; gap: 10px; margin-top: 8px; }
.contact-card-actions .icon-link { gap: 4px; font-size: 12px; font-weight: 500; opacity: 0.75; }

/* Same [hidden]-defeating bug as .row-add-contact above — this block
   carries the actual Closed-Won gate (lead_detail.html's
   {% if lead.status != "Closed Won" %}hidden{% endif %}), so an
   unconditional `display` here made it show regardless of status. */
.add-contact-block:not([hidden]) { display: flex; }
.add-contact-block { margin-top: 24px; align-items: center; gap: 10px; }
.add-contact-block .add-contact-done { font-size: 12.5px; font-weight: 600; color: #2f8a4e; }
.add-contact-status { font-size: 12px; color: var(--text-muted); }
.add-contact-status.is-error { color: #b3441e; }
.add-contact-status.is-success { color: #2f8a4e; }

.clinical-intake { margin-top: 20px; background: oklch(95% 0.008 90); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.clinical-intake-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.clinical-intake-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
.field-label { font-size: 12px; color: var(--text-muted); }

.detail-pane section { margin-top: 28px; }
.detail-pane section h2 { font-family: var(--serif); font-size: 18px; font-weight: 600; margin: 0 0 12px 0; }

.tag-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px 0; }
.tag-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.85em;
}
.tag-pill form { display: contents; }
.tag-remove {
  background: none;
  color: #999;
  border: none;
  border-radius: 50%;
  padding: 0 6px;
  line-height: 1.4;
  font-size: 1em;
  cursor: pointer;
}
.tag-remove:hover { color: #b00020; }
.tag-form { display: flex; gap: 8px; max-width: 480px; }
.tag-form input { flex: 1; }
.pq-sync-note { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.activity-timeline { max-width: 600px; }
.activity-entry { display: flex; gap: 14px; padding-bottom: 16px; }
.activity-entry-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex-shrink: 0; }
.activity-entry-body p { margin: 4px 0 0 0; }
.method-chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--accent-tint); color: var(--accent-text); margin-left: 6px; }
.pq-chip { font-size: 10.5px; padding: 2px 8px; border-radius: 999px; background: oklch(94% 0.02 240); color: oklch(38% 0.04 240); margin-left: 6px; }

.activity-entry-confirmed { display: flex; align-items: center; gap: 8px; padding: 6px 0 6px 0; }
.confirmed-datetime { font-size: 12.5px; color: #2f8a4e; font-weight: 500; }

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  font-family: var(--sans);
}
.login-title { font-family: var(--serif); font-weight: 600; }

.error { color: #b00020; }

.dev-banner {
  background: #b00020;
  color: white;
  text-align: center;
  padding: 6px;
  font-weight: 600;
  font-size: 0.85em;
}

#new-lead-modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: 520px;
  width: 90vw;
  box-shadow: 0 10px 40px oklch(20% 0.01 90 / 0.25);
}
#new-lead-modal::backdrop { background: oklch(20% 0.01 90 / 0.45); }
#new-lead-modal .lead-form { max-width: none; }
#new-lead-modal .lead-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 0 24px;
}
#new-lead-modal .lead-form-header h2 { font-family: var(--serif); font-size: 19px; margin: 0; }
#new-lead-modal .modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
#new-lead-modal .modal-close:hover { color: var(--accent-text); }

@media (max-width: 900px) {
  .split-view { flex-direction: column; height: auto; }
  .list-pane { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .contact-cards, .clinical-intake-grid { grid-template-columns: 1fr; }
}

.activity-note { resize: none; field-sizing: content; max-height: 8em; }
.activity-entry { position: relative; }
.activity-entry-actions { margin-left: auto; display: flex; gap: 4px; align-items: flex-start; opacity: 0; transition: opacity .12s; }
.activity-entry:hover .activity-entry-actions, .activity-entry-actions:focus-within, .activity-entry-editing .activity-entry-actions { opacity: 1; }
.activity-entry-confirmed .activity-entry-actions { align-items: center; }
.activity-entry { flex-wrap: wrap; }
.activity-entry-body { flex: 1; }
.activity-edit-form { flex-basis: 100%; margin-top: 8px; }
.activity-edit-form[hidden] { display: none; }
.delete-lead-form { margin: 32px 0 8px; }
.btn-danger:hover { border-color: #b00020; color: #b00020; }
.btn-secondary { background: none; color: var(--text-muted); border: 1px solid var(--border); padding: 8px 14px; border-radius: 4px; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-text); }
.list-pane-footer { padding: 10px 14px; font-size: 12px; }
.list-pane-footer a { color: var(--text-muted); }
.deleted-page { max-width: 720px; margin: 0 auto; padding: 24px 16px; }
.deleted-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.deleted-row-actions { display: flex; gap: 8px; }
