/* ═══════════════════════════════════════════════════════════════
   HIGH 5 CONNECT CRM — V2 Pipeline (Board + List)
   ═══════════════════════════════════════════════════════════════ */

/* ─── Pipeline Header ───────────────────────────────────────── */
.pipeline-header {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.pipeline-header-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
}

.pipeline-view-toggle {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--r-md);
  padding: 2px;
}

.pipeline-view-btn {
  padding: var(--s1) var(--s3);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  transition: all var(--t-fast);
}

.pipeline-view-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.pipeline-filters {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: auto;
}

.pipeline-filter-select {
  padding: var(--s1) var(--s3);
  font-size: var(--text-xs);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  min-height: 32px;
}

/* ─── Board View ────────────────────────────────────────────── */
.pipeline-board {
  display: flex;
  gap: var(--s3);
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: var(--s4);
  -webkit-overflow-scrolling: touch;
  height: calc(100dvh - 140px);
  flex-shrink: 0;
}

.pipeline-board::-webkit-scrollbar {
  height: 6px;
}

/* ─── Board Column ──────────────────────────────────────────── */
.board-col {
  flex-shrink: 0;
  width: 260px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

@media (min-width: 1025px) {
  .board-col {
    width: 280px;
  }
}

.board-col-header {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s3);
  border-radius: var(--r-md) var(--r-md) 0 0;
  position: sticky;
  top: 0;
  z-index: var(--z-base);
}

.board-col-header-top {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.board-col-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--r-full);
  flex-shrink: 0;
}

.board-col-name {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  flex: 1;
}

.board-col-count {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-label);
}

.board-col-value {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
}

.board-col-cards {
  flex: 1;
  overflow-y: auto;
  padding: var(--s2);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  background: var(--bg-page);
  border-radius: 0 0 var(--r-md) var(--r-md);
  border: 1px solid var(--border);
  border-top: none;
  min-height: 60px;
}

.board-col-cards.drag-over {
  background: var(--accent-bg);
  border-color: var(--accent);
}

/* ─── Pipeline Card ─────────────────────────────────────────── */
.pipeline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: box-shadow var(--t-fast), transform var(--t-fast);
  display: flex;
  overflow: hidden;
  flex-shrink: 0;
}

.pipeline-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--card-accent, var(--border));
}

.pipeline-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
}

.pipeline-card-accent {
  width: 4px;
  background: var(--card-accent, var(--accent));
  flex-shrink: 0;
  border-radius: var(--r-md) 0 0 var(--r-md);
}

.pipeline-card-inner {
  flex: 1;
  padding: var(--s3);
  min-width: 0;
}

.pipeline-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: var(--s1);
}

.pipeline-card-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.pipeline-card-name {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  cursor: pointer;
}

.pipeline-card-name:hover {
  color: var(--accent);
  text-decoration: underline;
}

.pipeline-card-title {
  font-size: var(--text-xs);
  color: var(--text-label);
  margin-bottom: var(--s2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
}

.pipeline-card-value {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}

.pipeline-card-aging {
  font-size: var(--text-xs);
  color: var(--text-label);
  display: flex;
  align-items: center;
  gap: 3px;
}

.pipeline-card-aging.overdue {
  color: var(--red);
  font-weight: 600;
}

.pipeline-card-meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: var(--s2);
}

.pipeline-card-source {
  font-size: var(--text-xs);
  color: var(--text-label);
}

.pipeline-card-rep {
  font-size: var(--text-xs);
  color: var(--text-label);
  margin-left: auto;
}

.pipeline-card-indicators {
  display: flex;
  align-items: center;
  gap: var(--s1);
  margin-left: auto;
}

.pipeline-card-indicator {
  font-size: 10px;
  color: var(--text-label);
}

/* ─── List View ─────────────────────────────────────────────── */
.pipeline-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.pipeline-list-header {
  display: grid;
  grid-template-columns: 1.6fr 1.6fr 140px 120px 100px 70px;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  background: var(--bg-input);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  border-bottom: 1px solid var(--border);
}

.pipeline-list-row {
  display: grid;
  grid-template-columns: 1.6fr 1.6fr 140px 120px 100px 70px;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
  align-items: center;
  cursor: pointer;
  transition: background var(--t-fast);
}

.pipeline-list-address {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pipeline-list-aging-over {
  color: var(--red);
  font-weight: 700;
}

.pipeline-list-row:hover {
  background: var(--bg-hover);
}

.pipeline-list-row:last-child {
  border-bottom: none;
}

.pipeline-list-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.pipeline-list-sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
}

.pipeline-list-stage {
  font-size: var(--text-xs);
}

.pipeline-list-value {
  font-weight: 700;
  font-size: var(--text-sm);
}

.pipeline-list-aging {
  font-size: var(--text-xs);
  color: var(--text-label);
  text-align: right;
}

/* Mobile pipeline header */
@media (max-width: 640px) {
  .pipeline-header-row {
    flex-direction: column;
    align-items: stretch;
  }

  .pipeline-filters {
    display: none;
  }

  .pipeline-view-toggle {
    align-self: flex-start;
  }
}

/* ─── Mobile List View — Card-style rows ───────────────────── */
@media (max-width: 640px) {
  .pipeline-list {
    background: none;
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    gap: var(--s2);
  }

  .pipeline-list-header {
    display: none;
  }

  .pipeline-list-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: var(--s1) var(--s3);
    padding: var(--s3) var(--s4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    border-left: 4px solid var(--dynamic-color, var(--accent));
  }

  /* Name + job title: top-left */
  .pipeline-list-row > *:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  /* Stage badge: top-right */
  .pipeline-list-row > *:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: flex-start;
  }

  /* Source: bottom-left */
  .pipeline-list-row > *:nth-child(3) {
    grid-column: 1;
    grid-row: 2;
    font-size: var(--text-xs);
    color: var(--text-label);
  }

  /* Value: bottom-right */
  .pipeline-list-row > *:nth-child(4) {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  /* Aging: hide on mobile (info is in the stage badge area) */
  .pipeline-list-row > *:nth-child(5) {
    display: none;
  }
}

/* ─── Mobile Board: Horizontal Swipe Kanban ────────────────── */
@media (max-width: 640px) {
  .pipeline-board {
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Fill remaining viewport: subtract topbar, header, dots+padding, bottomnav */
    min-height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top) - 130px - var(--bottomnav-height));
  }

  .pipeline-board::-webkit-scrollbar {
    display: none;
  }

  .board-col {
    width: 100%;
    min-width: 100%;
    flex-shrink: 0;
    scroll-snap-align: start;
    max-height: none;
    display: flex;
    flex-direction: column;
  }

  .board-col-cards {
    max-height: none;
    min-height: 200px;
    flex: 1;
    overflow-y: auto;
  }
}

/* ─── Mobile Stage Indicator (dots only, below board) ──────── */
.pipeline-stage-indicator {
  display: none;
}

@media (max-width: 640px) {
  .pipeline-stage-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s2) 0 var(--s3);
  }

  .stage-indicator-dots {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .stage-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    background: var(--border);
    transition: all 200ms ease;
    flex-shrink: 0;
  }

  .stage-indicator-dot.active {
    width: 10px;
    height: 10px;
    background: var(--accent);
    box-shadow: 0 0 6px rgba(6, 139, 195, 0.4);
  }
}

/* ─── Quick Filter Pills ───────────────────────────────────── */
.pipeline-quick-filters {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  padding-bottom: var(--s1);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.pipeline-quick-filters::-webkit-scrollbar {
  display: none;
}

.pipeline-quick-filter {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: var(--s1) var(--s3);
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 150ms ease;
  background: var(--bg-card);
  cursor: pointer;
}

.pipeline-quick-filter:hover {
  background: var(--bg-hover);
  border-color: var(--text-label);
  transform: translateY(-1px);
}

.pipeline-quick-filter.active {
  background: var(--navy-base);
  color: var(--text-inverse);
  border-color: var(--navy-base);
}

.pipeline-quick-filter-count {
  background: rgba(255, 255, 255, 0.2);
  font-size: 10px;
  font-weight: 700;
  padding: 0 4px;
  border-radius: var(--r-full);
  min-width: 16px;
  text-align: center;
}

.pipeline-quick-filter:not(.active) .pipeline-quick-filter-count {
  background: var(--bg-input);
  color: var(--text-label);
}

/* ─── Sort Dropdown ────────────────────────────────────────── */
.pipeline-sort {
  display: flex;
  align-items: center;
  gap: var(--s1);
  font-size: var(--text-xs);
  color: var(--text-label);
}

.pipeline-sort select {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
}

/* ─── Pipeline Card Row (Hero + Content) ───────────────────── */
.pipeline-card-row {
  display: flex;
  gap: var(--s2);
  align-items: flex-start;
}

.pipeline-card-hero {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  object-fit: cover;
  flex-shrink: 0;
}

.pipeline-card-content {
  flex: 1;
  min-width: 0;
}

.pipeline-card-address {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* ─── Pipeline Card Indicators (insurance, tasks, follow-up) ── */
.pipeline-card-indicators {
  display: flex;
  gap: var(--s1);
  flex-wrap: wrap;
  margin-top: var(--s2);
}

.pipeline-card-indicator {
  display: inline-flex;
  align-items: center;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  white-space: nowrap;
  line-height: 1.4;
}

.indicator-insurance {
  background: #dbeafe;
  color: #1e40af;
}

.indicator-tasks {
  background: #fef3c7;
  color: #92400e;
}

.indicator-followup {
  background: #e0f4fc;
  color: var(--accent, #068bc3);
}

.indicator-overdue {
  background: #fde8e8;
  color: #dc2626;
}

/* Scheduled-on-calendar chip — matches the red Job Schedule bar on
   the calendar so the visual link between "card has chip" and "calendar
   has red bar" is obvious. Leading calendar+check icon stands in for
   the word "Scheduled". */
.indicator-schedule {
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.indicator-schedule .indicator-icon {
  flex-shrink: 0;
  margin-top: -1px; /* optical centering against the cap-height text */
}

/* ─── Pipeline Card Tags ───────────────────────────────────── */
.pipeline-card-tags {
  display: flex;
  gap: var(--s1);
  margin-top: var(--s2);
  flex-wrap: wrap;
}

.pipeline-card-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--r-full);
}

/* ─── Pipeline Card Task Count ─────────────────────────────── */
.pipeline-card-tasks {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-label);
}

.pipeline-card-tasks.has-overdue {
  color: var(--red);
  font-weight: 600;
}
