/* ============================================
   LEADS - Lead List, Lead Detail Panel
   ============================================ */

/* Leads Container */
.leads-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  height: calc(100vh - 180px);
  position: relative;
}

.leads-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid var(--border);
}

.list-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.list-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Lead Detail - overlays on top of table */
.lead-detail {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  overflow-y: auto;
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  width: var(--pane-width, 550px);
  height: 100%;
  z-index: 30;
}

.leads-container.detail-open .lead-detail {
  display: block;
}

/* Resize handle on left edge of detail pane */
.detail-resize-handle {
  display: none;
  position: absolute;
  top: 0;
  z-index: 40;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  border-radius: 4px;
  transition: background 0.15s;
}

.leads-container.detail-open .detail-resize-handle {
  display: block;
  /* Positioned via JS to align with pane left edge */
  right: var(--pane-width, 550px);
  margin-right: -4px;
}

.detail-resize-handle:hover,
.detail-resize-handle.dragging {
  background: var(--primary);
  opacity: 0.3;
}

/* Add padding so table can scroll out from behind the pane */
.leads-container.detail-open .table-container {
  scroll-padding-right: var(--pane-width, 550px);
}

.leads-container.detail-open #leadsTable {
  margin-right: var(--pane-width, 550px);
}

/* Sticky name column when pane is open and table scrolls horizontally */
.leads-container.detail-open #leadsTable th[data-col="name"],
.leads-container.detail-open #leadsTable td[data-col="name"] {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-card);
}

.leads-container.detail-open #leadsTable tr:hover td[data-col="name"] {
  background: var(--bg);
}

.leads-container.detail-open #leadsTable tr.selected td[data-col="name"] {
  background: var(--primary-subtle, #eff6ff);
}

/* Sticky Detail Header */
.detail-sticky-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px 16px 20px;
}

.detail-sticky-header .detail-header {
  margin-bottom: 0;
}

.detail-content {
  padding: 20px;
}

/* Close Button — pinned top-right in sticky header gutter */
.detail-close-btn {
  position: absolute;
  top: 8px;
  right: 6px;
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  padding: 2px 5px;
  cursor: pointer;
  color: var(--text-light);
  opacity: 0.4;
  transition: opacity 0.15s;
}

.detail-close-btn:hover {
  opacity: 1;
}

/* Fade-in animation for lead switch */
@keyframes detailFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-fade-in {
  animation: detailFadeIn 0.25s ease-out;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.detail-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-name {
  font-size: 20px;
  font-weight: 600;
}

.detail-name.clickable,
.value.clickable {
  cursor: pointer;
}

.detail-name.clickable:hover,
.value.clickable:hover {
  color: var(--primary);
}

.detail-category {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-category-quick {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.detail-category-quick .lead-category-btn {
  padding: 4px 10px;
  font-size: 12px;
  min-width: 32px;
}

.detail-category-quick .lead-category-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.detail-id {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
}

.lost-reason {
  font-size: 11px;
  color: var(--danger);
  margin-top: -15px;
  margin-bottom: 15px;
}

.detail-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Detail Sections */
.detail-section {
  margin-bottom: 20px;
}

.detail-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.section-header h4 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* Assignment Section - Badge Style */
.assignment-section {
  padding: 8px 0;
}

.assignment-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.assistant-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

/* Full access - muted (they see everything anyway) */
.assistant-badge.full-access {
  background: #f3f4f6;
  color: #6b7280;
  cursor: default;
}

/* Restricted - not assigned */
.assistant-badge.restricted {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px dashed #d1d5db;
}

/* Restricted - assigned */
.assistant-badge.restricted.assigned {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.assistant-badge.restricted:hover {
  background: #e5e7eb;
}

.assistant-badge .badge-check {
  font-size: 10px;
}

/* Detail Grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-field {
  font-size: 13px;
}

.detail-field .label {
  color: var(--text-light);
  font-size: 11px;
}

.detail-field .value {
  font-weight: 500;
  white-space: pre-wrap;
}

.detail-field.full-width {
  grid-column: span 2;
}

/* Secondary Info */
.secondary-info {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  opacity: 0.85;
}

.secondary-info .detail-field .label {
  font-size: 10px;
}

.secondary-info .detail-field .value {
  font-size: 12px;
  font-weight: normal;
}

/* Appointment Stats */
.appt-stats {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 10px;
}

/* Detail Footer */
.detail-footer {
  margin-top: 30px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 15px;
}

/* Days since last contact column */
.days-cold {
  color: var(--danger);
  font-weight: 600;
}

.days-warm {
  color: var(--warning);
}

.days-recent {
  color: var(--success);
}

/* Concepts Container */
.concepts-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 180px);
}

.concepts-summary {
  display: flex;
  gap: 15px;
  padding: 10px 15px;
}

.summary-card {
  background: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius);
  text-align: center;
}

.summary-card .label {
  display: block;
  font-size: 12px;
  color: var(--text-light);
}

.summary-card .value {
  display: block;
  font-size: 20px;
  font-weight: 600;
  color: var(--primary);
}

/* Concepts in Detail */
.concepts-list {
  margin-top: 10px;
}

/* Backdrop for mobile drawer — hidden on desktop */
.lead-detail-backdrop {
  display: none;
}

/* Responsive: Mobile (<900px) — single column + slide-in drawer */
@media (max-width: 899px) {
  .leads-container,
  .leads-container.detail-open {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .detail-resize-handle {
    display: none !important;
  }

  .lead-detail {
    display: block;
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 450px;
    height: 100vh;
    z-index: 500;
    transition: right 0.3s;
    border-radius: 0;
  }

  .lead-detail.active {
    right: 0;
  }

  .lead-detail-backdrop.active {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 499;
    opacity: 1;
  }
}
