﻿/* Redesign: page styles for the leads area. Uses tokens from /theme.css only.
   Pages: Home, All leads (list, map), Find leads, Pipeline, Tasks, Templates, Settings.
   Their sections carry .crm-page (set by crm.js / research.js) and the dialogs carry
   .crm-dialog plus their own class, so nothing here reaches other areas. */

/* ---------- Shared ---------- */

.crm-page { --pad-x: 18px; }
.crm-page .page-head > div:first-child { min-width: 0; }
.crm-page .page-head .actions:empty { display: none; }
.crm-page .page-head .actions > .import-btn { display: contents; }
.crm-page .cols { column-gap: 16px; }
.crm-page .card > h2 { display: flex; align-items: center; gap: 8px; }
.crm-page .card > h2 + .muted.small { margin: -6px 0 10px; }

.crm-page .count,
.crm-dialog .count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.crm-page .card > .empty,
.crm-dialog .empty { padding: 28px 12px; }
.crm-page .empty p,
.crm-dialog .empty p { margin: 0; max-width: 46ch; font-size: 0.84375rem; }

.crm-page .chips,
.crm-dialog .chips { gap: 6px; margin-top: 8px; }
.crm-page .inline-form input,
.crm-page .inline-form select,
.crm-dialog .inline-form input,
.crm-dialog .inline-form select { margin-top: 0; }
.crm-page .modal-actions,
.crm-dialog .modal-actions { flex-wrap: wrap; }

@media (max-width: 899px) {
  .crm-page { --pad-x: 14px; }
}

/* Phone: header buttons sit in one row that scrolls sideways */
@media (max-width: 640px) {
  /* nowrap: in a wrapping column flexbox the stretched rows take their content width */
  .crm-page .page-head { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 12px; }
  .crm-page .page-head .actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -14px;
    padding: 3px 14px;
    scrollbar-width: none;
  }
  .crm-page .page-head .actions::-webkit-scrollbar { display: none; }
  .crm-page .page-head .actions > *,
  .crm-page .page-head .actions button { flex: none; }
}

/* ---------- KPI tiles ---------- */

.crm-page .tile { min-width: 0; gap: 3px; container-type: inline-size; }
.crm-page .tile strong.fit { white-space: nowrap; font-size: min(1.5rem, calc(100cqi / (var(--len, 12) * 0.5))); }
@media (max-width: 899px) {
  .crm-page .tile strong.fit { font-size: min(1.25rem, calc(100cqi / (var(--len, 12) * 0.5))); }
}
.crm-page .tile-label { display: flex; align-items: center; gap: 6px; }
.crm-page .tile-label svg { width: 15px; height: 15px; flex: none; color: var(--faint); transition: color 0.15s; }
.crm-page a.tile:hover .tile-label svg { color: var(--accent-text); }
.crm-page .tile strong { overflow-wrap: anywhere; }
.crm-page .tile strong .unit {
  margin-right: 1px;
  font-size: 0.58em;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
  vertical-align: 0.18em;
}

/* ---------- Home ---------- */

#page-home .home-list li {
  justify-content: flex-start;
  gap: 12px;
  margin: 0 calc(var(--pad-x) * -1);
  padding: 9px var(--pad-x);
}
#page-home .home-list li.clickable:hover { background: var(--surface-2); }
#page-home .home-list li:last-child { margin-bottom: -6px; }
#page-home .row-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
}
#page-home .row-icon svg { width: 16px; height: 16px; }
#page-home .row-icon[data-kind="reply"] { background: var(--danger-soft); color: var(--danger); }
#page-home .row-icon[data-kind="follow"] { background: var(--accent-soft); color: var(--accent-text); }
#page-home .row-icon[data-kind="task"] { background: var(--violet-soft); color: var(--violet); }
#page-home .row-icon[data-kind="lead"] { background: var(--teal-soft); color: var(--teal); }
#page-home .row-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#page-home .row-text strong { font-weight: 600; }
#page-home .home-list .due,
#page-home .home-list .score { flex: none; }

#page-home .stage-bars { gap: 2px; }
#page-home .stage-row {
  grid-template-columns: 88px minmax(0, 1fr) 48px;
  gap: 12px;
  margin: 0 -8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.84375rem;
  color: var(--text-2);
  text-decoration: none;
}
#page-home .stage-row:hover { background: var(--surface-2); text-decoration: none; }
#page-home .stage-row strong { font-weight: 600; color: var(--text); }
#page-home .stage-row .track { height: 6px; background: var(--surface-3); }
#page-home .track span[data-stage="new"] { background: var(--faint); }
#page-home .track span[data-stage="contacted"] { background: var(--accent); }
#page-home .track span[data-stage="interested"] { background: var(--warning); }
#page-home .track span[data-stage="meeting"] { background: var(--teal); }
#page-home .track span[data-stage="proposal"] { background: var(--violet); }
#page-home .track span[data-stage="won"] { background: var(--success); }
#page-home .track span[data-stage="lost"] { background: var(--danger); }

#page-home .empty-state p { color: var(--text-2); }
#page-home .empty-state ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); }

/* ---------- All leads: filters ---------- */

#page-leads .filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
#page-leads .filter-search { position: relative; flex: 2 1 260px; margin: 0; }
#page-leads .filter-search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}
#page-leads .filter-search input { margin: 0; padding-left: 32px; }
#page-leads .filter-selects { display: contents; }
#page-leads .filters select { flex: 1 1 140px; width: auto; min-width: 0; margin: 0; }

#page-leads .view-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 0 10px;
}
#page-leads .lead-count { margin: 0; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
#page-leads .view-row .actions { gap: 8px; }
#page-leads .view-row select { width: auto; margin: 0; min-height: 32px; font-size: 0.8125rem; }
#page-leads .tabs { margin: 0; }
#page-leads .tabs > button svg { width: 15px; height: 15px; }

@media (max-width: 640px) {
  #page-leads .filter-search { flex: 1 1 100%; }
  #page-leads .filter-selects {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
    overflow-x: auto;
    margin: 0 -14px;
    padding: 2px 14px;
    scrollbar-width: none;
  }
  #page-leads .filter-selects::-webkit-scrollbar { display: none; }
  #page-leads .filter-selects select {
    flex: none;
    width: auto;
    max-width: 75vw;
    min-height: 34px;
    padding-left: 12px;
    border-radius: 999px;
    font-size: 0.8125rem;
  }
  /* Count and Table/Map on one line, the two selects on the next */
  #page-leads .view-row .actions { display: contents; }
  #page-leads .view-row .lead-count { order: 1; flex: 1 1 auto; }
  #page-leads .view-row .tabs { order: 2; flex: none; flex-wrap: nowrap; }
  #page-leads .view-row select { order: 3; flex: 1 1 40%; min-width: 0; }
}

/* ---------- All leads: table ---------- */

#page-leads .leads-card { margin: 0; }
#page-leads .leads-card .table-wrap {
  max-height: max(360px, calc(100dvh - 300px));
  overflow: auto;
  overscroll-behavior: contain;
}
#page-leads .leads-table { font-size: 0.8125rem; }
#page-leads .leads-table th { z-index: 2; }
#page-leads .leads-table td { padding: 8px 12px; vertical-align: middle; }
#page-leads .leads-table th:first-child,
#page-leads .leads-table td:first-child { position: sticky; left: 0; }
#page-leads .leads-table th:first-child { z-index: 3; }
#page-leads .leads-table td:first-child { z-index: 1; background: var(--surface); }
#page-leads .leads-table tbody tr.clickable:hover td:first-child {
  background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--surface);
}
#page-leads .lt-name { width: 30%; min-width: 190px; }
#page-leads .lt-name strong { font-weight: 600; overflow-wrap: anywhere; }
#page-leads .lt-name .muted { margin-top: 1px; }
#page-leads .lt-email { max-width: 230px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#page-leads .leads-table .pill { margin: 0 4px 0 0; }
#page-leads .leads-table .phone-flag { margin-left: 5px; }

@media (max-width: 899px) {
  #page-leads .leads-card .table-wrap { max-height: none; }
}
@media (max-width: 640px) {
  #page-leads .lt-name { width: 150px; min-width: 150px; }
}

/* ---------- All leads: map ---------- */

#page-leads .map-card { margin: 0; }
#page-leads .map-tools { gap: 10px; padding: 8px 12px; }
#page-leads .map-tools label.check { margin: 0 0 0 auto; }
#page-leads .map { height: max(380px, calc(100dvh - 440px)); }
#page-leads .map-legend { gap: 6px 14px; padding: 9px 14px; font-size: 0.78125rem; color: var(--text-2); }
#page-leads .map-dot { width: 9px; height: 9px; border: 0; box-shadow: none; }
#page-leads .map-ring { width: 11px; height: 11px; }

#page-leads .leaflet-container { background: var(--surface-3); }
#page-leads .leaflet-bar { border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
#page-leads .leaflet-bar a { background: var(--surface); color: var(--text); border-bottom-color: var(--border); }
#page-leads .leaflet-bar a:hover { background: var(--surface-3); }
#page-leads .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--muted); }
#page-leads .leaflet-control-attribution a { color: var(--accent-text); }
#page-leads .leaflet-popup-content-wrapper,
#page-leads .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); }
#page-leads .leaflet-popup-content-wrapper { border: 1px solid var(--border); border-radius: var(--radius-lg); }
#page-leads .leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
#page-leads .map-pop { gap: 5px; font: 400 0.8125rem/1.45 var(--font); }
#page-leads .leaflet-container .map-pop .muted { color: var(--muted); }
#page-leads .map-pop button { margin-top: 6px; }
:root[data-theme="dark"] #page-leads .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #page-leads .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6); }
}

/* ---------- Pipeline board ---------- */

#page-pipeline {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h) - 80px);
  min-height: 460px;
}
#page-pipeline .board {
  flex: 1 1 auto;
  min-height: 0;
  grid-auto-columns: minmax(248px, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  gap: 12px;
  padding: 0 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
}
#page-pipeline .column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  scroll-snap-align: start;
  transition: border-color 0.15s, background-color 0.15s;
}
#page-pipeline .column.drop { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
#page-pipeline .column-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 -8px;
  padding: 10px 12px 8px;
  background: inherit;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
#page-pipeline .column-head .pill { margin: 0; }
#page-pipeline .column-head .grow-right { font-variant-numeric: tabular-nums; }
#page-pipeline .deal {
  display: grid;
  gap: 2px;
  flex: none;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
#page-pipeline .deal:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
#page-pipeline .deal:active { cursor: grabbing; }
#page-pipeline .deal.dragging { opacity: 0.45; }
#page-pipeline .deal strong { font-size: 0.84375rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
#page-pipeline .deal > .muted.small { font-size: 0.75rem; }
#page-pipeline .deal-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 6px; }
#page-pipeline .deal-foot .score { height: 20px; min-width: 28px; font-size: 0.6875rem; }
#page-pipeline .deal-value { font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
#page-pipeline .deal-foot .due { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; font-size: 0.75rem; white-space: nowrap; }
#page-pipeline .deal-foot .due svg { width: 12px; height: 12px; }
#page-pipeline .column-empty {
  margin: 0;
  padding: 18px 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
  font-size: 0.78125rem;
  color: var(--faint);
}

@media (max-width: 899px) {
  #page-pipeline {
    height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: 400px;
  }
  #page-pipeline .board {
    grid-auto-columns: min(82vw, 300px);
    margin: 0 -14px;
    padding: 0 14px 8px;
    scroll-padding: 0 14px;
    scroll-snap-type: x mandatory;
  }
}

/* ---------- Tasks (page and lead dialog) ---------- */

.crm-page .tasks,
.lead-dialog .tasks { list-style: none; margin: 0; padding: 0; }
.crm-page .task,
.lead-dialog .task {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.crm-page .task:first-child,
.lead-dialog .task:first-child { border-top: 0; }
.crm-page .task input[type="checkbox"],
.lead-dialog .task input[type="checkbox"] { width: 17px; height: 17px; margin: 0; }
.crm-page .task-title,
.lead-dialog .task-title { min-width: 0; overflow-wrap: anywhere; line-height: 1.45; }
.crm-page .task.done .task-title,
.lead-dialog .task.done .task-title { color: var(--muted); text-decoration: line-through; }
.crm-page .task-title .pill,
.lead-dialog .task-title .pill { height: 20px; margin: 0 0 0 6px; font-size: 0.6875rem; vertical-align: 1px; }
.crm-page .task-title .muted.small,
.lead-dialog .task-title .muted.small { margin-top: 2px; }
.crm-page .task .icon-btn,
.lead-dialog .task .icon-btn { width: 28px; min-width: 28px; height: 28px; min-height: 28px; color: var(--faint); }
.crm-page .task .icon-btn svg,
.lead-dialog .task .icon-btn svg { width: 15px; height: 15px; }
.crm-page .task .icon-btn:hover:not(:disabled),
.lead-dialog .task .icon-btn:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

#page-tasks .task { margin: 0 calc(var(--pad-x) * -1); padding: 9px var(--pad-x); }
#page-tasks .task:hover { background: var(--surface-2); }
#page-tasks .task-group:last-child { margin-bottom: 0; }
#page-tasks .task-group[data-group="overdue"] .count { background: var(--danger-soft); color: var(--danger); }
#page-tasks .task-group[data-group="today"] .count { background: var(--accent-soft); color: var(--accent-text); }

.crm-page .task-form,
.lead-dialog .task-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.crm-page .task-form input:not([type="date"]),
.lead-dialog .task-form input:not([type="date"]) { flex: 3 1 220px; width: auto; min-width: 0; }
.crm-page .task-form input[type="date"],
.lead-dialog .task-form input[type="date"] { flex: 0 1 150px; width: auto; }
.crm-page .task-form select,
.lead-dialog .task-form select { flex: 1 1 150px; width: auto; min-width: 0; }
.crm-page .task-form button,
.lead-dialog .task-form button { flex: none; }
.lead-dialog .task-form input:not([type="date"]) { flex-basis: 100%; }
.lead-dialog .tasks + .task-form { margin-top: 8px; }

/* ---------- Templates ---------- */

#page-templates .sheets-card .chips { margin-top: 10px; }
#page-templates .template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
  gap: 14px;
}
#page-templates .template { display: flex; flex-direction: column; gap: 10px; margin: 0; }
#page-templates .template-head { align-items: flex-start; }
#page-templates .template-name { min-width: 0; }
#page-templates .template-name h3 { margin: 0 0 2px; font-size: 0.9375rem; font-weight: 600; }
#page-templates .template-name p { overflow-wrap: anywhere; }
#page-templates .template-head .actions { flex: none; gap: 2px; }
#page-templates .template-head .icon-btn:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
#page-templates .template-body {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

/* ---------- Settings ---------- */

#page-settings { max-width: 900px; }
#page-settings .card > .muted.small,
#page-settings .card > .notice { margin: -4px 0 4px; }
#page-settings .form .modal-actions { margin-top: 4px; }
#page-settings .key-row {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 400px);
  gap: 10px 28px;
  padding: 14px 0;
}
#page-settings .key-row:last-child { padding-bottom: 2px; }
#page-settings .key-name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#page-settings .key-info p { margin-top: 3px; }
#page-settings .key-row .inline-form { flex-wrap: nowrap; }
#page-settings .key-row .inline-form input { flex: 1 1 auto; min-width: 0; }
#page-settings .data-card .button { margin-top: 10px; }
@media (max-width: 760px) {
  #page-settings .key-row { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Find leads ---------- */

#page-find .find-top,
#page-find .find-settings { align-items: start; }
#page-find .scope-toggle {
  display: inline-flex;
  gap: 2px;
  margin: 0 0 14px;
  padding: 3px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 10px;
}
#page-find .scope-toggle label.check {
  position: relative;
  gap: 6px;
  min-height: 28px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
}
#page-find .scope-toggle label.check input { position: absolute; opacity: 0; pointer-events: none; }
#page-find .scope-toggle label.check svg { width: 15px; height: 15px; }
#page-find .scope-toggle label.check:hover { color: var(--text); }
#page-find .scope-toggle label.check:has(input:checked) {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
#page-find .scope-toggle label.check:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-ring); }
#page-find .search-card .form > label.check { margin-bottom: 8px; font-size: 0.84375rem; }
#page-find .search-submit { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); gap: 8px 16px; }
#page-find .search-submit label.check { font-size: 0.84375rem; }

#page-find .preset-group { margin-top: 12px; }
#page-find .preset-group > p { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
#page-find .preset-group .chips { margin-top: 6px; }
#page-find #research-summary > p:not(.muted) { margin-bottom: 4px; font-weight: 500; }
#page-find #research-summary .modal-actions { margin-top: 14px; }

#page-find .sweep-types { gap: 4px 16px; margin: 4px 0 14px; }
#page-find .sweep-types label.check { font-size: 0.8125rem; }
#page-find .sweep-card .inline-form select { flex: 0 1 260px; width: auto; min-width: 0; }
#page-find .sweep-card > .muted.small:not(:first-of-type) { margin-top: 8px; }
#page-find .google-cap { gap: 8px; margin-top: 14px; padding-top: 14px; }
#page-find .google-cap input { display: inline-block; flex: none; width: 110px; margin: 0; }

#page-find .jobs { list-style: none; margin: 0; padding: 0; }
#page-find .job {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 16px;
  margin: 0 calc(var(--pad-x) * -1);
  padding: 10px var(--pad-x);
  border-top: 1px solid var(--border);
}
#page-find .job:first-child { border-top: 0; padding-top: 4px; }
#page-find .job:hover { background: var(--surface-2); }
#page-find .job-head { grid-column: 1; justify-content: flex-start; gap: 8px; min-width: 0; }
#page-find .job-head strong { font-size: 0.84375rem; font-weight: 600; overflow-wrap: anywhere; }
#page-find .job-head .pill { flex: none; }
#page-find .job-detail { grid-column: 1; margin: 0; }
#page-find .job-actions { grid-column: 2; grid-row: 1 / span 2; justify-content: flex-end; gap: 4px; }
#page-find .job .bar { grid-column: 1 / -1; height: 4px; margin: 6px 0 2px; }
#page-find .job[data-status="done"] .bar span { background: color-mix(in srgb, var(--success) 55%, transparent); }
#page-find .job[data-status="failed"] .bar span { background: color-mix(in srgb, var(--danger) 55%, transparent); }
#page-find .job[data-status="cancelled"] .bar span { background: var(--faint); }
#page-find .job .preview { grid-column: 1 / -1; margin: 8px 0 2px; }
@media (max-width: 640px) {
  #page-find .sweep-card .inline-form select { flex: 1 1 100%; }
  #page-find .job { grid-template-columns: minmax(0, 1fr); }
  #page-find .job-actions { grid-column: 1; grid-row: auto; justify-content: flex-start; margin-top: 4px; }
}

#page-find .ai-card .stats { gap: 6px 16px; font-size: 0.84375rem; }
#page-find .ai-card .notice { margin-top: 0; }
#page-find .ai-row { gap: 8px; }
#page-find .ai-row input[type="number"] { flex: 0 1 100px; }
#page-find .models { margin-top: 10px; }
#page-find .models li { margin: 0 -6px; padding: 8px 6px; border-radius: var(--radius-sm); }
#page-find .models li:hover { background: var(--surface-2); }
#page-find .night-card .inline-form input[type="time"] { flex: 1 1 120px; width: auto; }

/* ---------- Lead dialog ---------- */

.lead-dialog .lead-head { display: flex; align-items: center; flex-wrap: nowrap; gap: 14px; margin: 0 0 16px; }
.lead-dialog .lead-photo {
  width: 52px;
  height: 52px;
  flex: none;
  padding: 0;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.lead-dialog .lead-avatar { display: grid; place-items: center; color: var(--muted); }
.lead-dialog .lead-avatar svg { width: 24px; height: 24px; }
.lead-dialog .lead-title { display: grid; gap: 6px; min-width: 0; }
.lead-dialog .lead-head .modal-title { margin: 0; font-size: 1.25rem; line-height: 1.25; overflow-wrap: anywhere; }
.lead-dialog .lead-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lead-dialog .lead-badges .pill { margin: 0; }
.lead-dialog .lead-badges .muted { margin-left: 2px; }

.lead-dialog .quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; padding: 0 0 16px; border-bottom: 1px solid var(--border); }
.lead-dialog .quick .button,
.lead-dialog .quick button { padding: 0 12px; font-size: 0.84375rem; }

.lead-dialog .lead-tabs { display: none; }
.lead-dialog .lead-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }

.lead-dialog .lead-sec-title { display: flex; align-items: center; gap: 7px; margin: 0 0 12px; font-size: 0.875rem; font-weight: 600; color: var(--text); }
.lead-dialog .lead-sec-title svg { width: 15px; height: 15px; color: var(--muted); }
.lead-dialog .lead-sec { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.lead-dialog .lead-side > .lead-sec:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.lead-dialog .lead-form .form-grid { gap: 0 12px; }
.lead-dialog .lead-form label { margin-bottom: 10px; }
.lead-dialog .lead-form .chips { margin-top: 6px; }
.lead-dialog .lead-form label.check { margin: 4px 0 10px; }
.lead-dialog .lead-form-actions { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.lead-dialog .lead-form-actions .link.danger { display: inline-flex; align-items: center; gap: 5px; padding-left: 0; }
.lead-dialog .lead-form-actions .link.danger svg { width: 15px; height: 15px; }
.lead-dialog.new .lead-form-actions { border-top: 0; padding-top: 0; }

.lead-dialog .contact-line {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.lead-dialog .contact-line > span { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.lead-dialog .contact-line > span > svg { width: 15px; height: 15px; flex: none; color: var(--muted); }

.lead-dialog .research {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.lead-dialog .research h3 { display: flex; align-items: center; gap: 7px; margin: 0 0 8px; font-size: 0.8125rem; font-weight: 600; }
.lead-dialog .research h3 svg { width: 15px; height: 15px; color: var(--violet); }
.lead-dialog .research p { margin: 4px 0; line-height: 1.5; overflow-wrap: anywhere; }
.lead-dialog .research > h3 + p:not(.small) { font-size: 0.875rem; color: var(--text); }
.lead-dialog .research .socials { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0 4px; }
.lead-dialog .research .socials .chip { height: 22px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.lead-dialog .research p.research-foot { margin: 10px 0 0; padding-top: 8px; border-top: 1px dashed var(--border-strong); }
.lead-dialog .research .stats.extra { gap: 4px 14px; font-size: 0.8125rem; }
.lead-dialog .research .stats.extra dd { font-weight: 500; }
.lead-dialog .lead-side > .notice { margin: 0 0 14px; }

.lead-dialog .log-form textarea { margin: 0; min-height: 64px; }
.lead-dialog .log-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.lead-dialog .log-actions select { flex: 0 1 190px; width: auto; min-width: 0; margin: 0; }
.lead-dialog .log-actions button { margin-left: auto; }

.lead-dialog .timeline { list-style: none; margin: 0; padding: 2px 4px 0 0; max-height: 380px; overflow: auto; }
.lead-dialog .timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  margin: 0;
  padding: 0 0 14px;
  border: 0;
}
.lead-dialog .timeline li::before { content: ""; position: absolute; left: 13.5px; top: 30px; bottom: 2px; width: 1px; background: var(--border); }
.lead-dialog .timeline li:last-child { padding-bottom: 4px; }
.lead-dialog .timeline li:last-child::before { display: none; }
.lead-dialog .tl-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-3); color: var(--muted); }
.lead-dialog .tl-icon svg { width: 14px; height: 14px; }
.lead-dialog .timeline li[data-type="call"] .tl-icon,
.lead-dialog .timeline li[data-type="whatsapp"] .tl-icon { background: var(--success-soft); color: var(--success); }
.lead-dialog .timeline li[data-type="email"] .tl-icon,
.lead-dialog .timeline li[data-type="reply"] .tl-icon { background: var(--accent-soft); color: var(--accent-text); }
.lead-dialog .timeline li[data-type="stage"] .tl-icon { background: var(--warning-soft); color: var(--warning); }
.lead-dialog .timeline li[data-type="meeting"] .tl-icon { background: var(--teal-soft); color: var(--teal); }
.lead-dialog .tl-body { min-width: 0; padding-top: 4px; }
.lead-dialog .timeline p { margin: 2px 0 0; font-size: 0.84375rem; line-height: 1.5; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 860px) {
  .lead-dialog .lead-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .lead-dialog .lead-tabs { display: flex; margin: 0 0 16px; }
  .lead-dialog .lead-tabs > button { flex: 1; }
  .lead-dialog .lead-layout[data-pane="activity"] > .lead-form { display: none; }
  .lead-dialog .lead-layout[data-pane="details"] > .lead-side { display: none; }
  .lead-dialog .lead-form > .lead-sec-title { display: none; }
}
@media (max-width: 640px) {
  .lead-dialog .lead-head { gap: 12px; padding-right: 36px; }
  .lead-dialog .lead-photo { width: 44px; height: 44px; border-radius: 10px; }
  .lead-dialog .lead-head .modal-title { font-size: 1.125rem; }
  .lead-dialog .quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -16px 14px;
    padding: 3px 16px 14px;
    scrollbar-width: none;
  }
  .lead-dialog .quick::-webkit-scrollbar { display: none; }
  .lead-dialog .quick > * { flex: none; }
}

/* ---------- Other dialogs: import, duplicates, composer, template editor ---------- */

.crm-dialog .dialog-sub { margin: -6px 0 14px; font-size: 0.84375rem; line-height: 1.55; }

.import-dialog .card.flush { margin: 0 0 16px; }
.import-dialog .table-wrap { max-height: min(52vh, 460px); overflow: auto; }
.import-dialog .import-map td { vertical-align: middle; }
.import-dialog .import-map td:nth-child(2) { min-width: 180px; }
.import-dialog .import-map select { min-width: 190px; min-height: 30px; margin: 0; padding: 0 30px 0 10px; font-size: 0.8125rem; }

.dup-dialog .dup-group { display: grid; gap: 12px; padding: 14px; background: var(--surface-2); box-shadow: none; }
.dup-dialog .dup-why { display: flex; align-items: flex-start; gap: 8px; margin: 0; color: var(--text-2); }
.dup-dialog .dup-why svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--accent-text); }
.dup-dialog .dup-cols { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 10px; }
.dup-dialog .dup-card { gap: 6px; padding: 12px 14px; background: var(--surface); border-radius: var(--radius); }
.dup-dialog .dup-card.keep { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dup-dialog .dup-card label.check { margin: 0 0 2px; font-weight: 550; color: var(--muted); }
.dup-dialog .dup-card.keep label.check { color: var(--accent-text); }
.dup-dialog .dup-card .stats.extra { grid-template-columns: 76px minmax(0, 1fr); gap: 3px 10px; font-size: 0.8125rem; }
.dup-dialog .dup-card .stats.extra dd { font-weight: 500; }
.dup-dialog .dup-group .modal-actions { margin-top: 0; }

.composer-dialog .form-grid { align-items: end; }
.composer-dialog .form-grid > label:only-child { grid-column: 1 / -1; }
.composer-dialog textarea { min-height: 240px; }
.composer-dialog .inline-form { flex-wrap: nowrap; }
.composer-dialog .inline-form select { flex: 1 1 auto; width: auto; min-width: 0; }
.composer-dialog .notice { margin-top: 0; }
.composer-dialog .composer-help { margin-top: 12px; line-height: 1.5; }

.template-dialog .template-edit { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.template-dialog .template-edit .chips { margin: 0 0 4px; }
.template-dialog .template-preview h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; }
.template-dialog .template-preview h3 svg { width: 15px; height: 15px; }
.template-dialog .preview { max-height: 470px; margin: 0; font-size: 0.84375rem; line-height: 1.55; }
@media (max-width: 760px) {
  .template-dialog .template-edit { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
