/* ---------------------------------------------------------------------------
   lead.css — the live lead card, the stage pips, and the drop animation.
   ---------------------------------------------------------------------------
   Also owns the dropped column's cards, because a dropped lead is the same
   object in a later state and the two have to read as a pair: the struck-through
   name and the ordinal are identical, only the density changes.

   DROPPED IS NOT AN ERROR. It uses the neutral --c-drop tokens throughout. A
   typical run drops more leads than it keeps, and sixteen red cards would train
   the operator to ignore red exactly when it starts meaning something.
--------------------------------------------------------------------------- */

.lead {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  transition: border-color var(--m-base) var(--m-ease),
              background var(--m-base) var(--m-ease),
              opacity var(--m-base) var(--m-ease);
  animation: lead-in var(--m-base) var(--m-ease);
}
@keyframes lead-in {
  from { opacity: 0; transform: translateY(var(--s-2)); }
  to   { opacity: 1; transform: none; }
}

.lead[data-status="listed"],
.lead[data-status="emailed"] { border-left-color: var(--c-ok); }
.lead[data-status="failed"] { border-left-color: var(--c-danger); }
.lead--working { border-left-color: var(--c-primary); }

/* ---- head ---------------------------------------------------------------- */
.lead__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: start;
}
.lead__ord {
  font-size: var(--t-sm);
  color: var(--c-fg-faint);
  padding-top: 2px;
}
.lead__id { min-width: 0; }
.lead__name {
  position: relative;
  display: inline-block;
  font-size: var(--t-lg);
  font-weight: var(--fw-semi);
}
.lead__sub {
  margin-top: var(--s-1);
  font-size: var(--t-sm);
  color: var(--c-fg-muted);
  gap: var(--s-1) var(--s-3);
}
.lead__addr[hidden], .lead__site[hidden], .lead__phone[hidden] { display: none; }
.lead__site { color: var(--c-primary); }

.lead__statecol {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-1);
  flex: none;
}
.lead__disc { font-size: var(--t-xs); }

/* ---- stage pips ---------------------------------------------------------- */
/* Eight dashes, one per pipeline stage, showing how far THIS lead has gone.
   Leads are pipelined, so the run's own status cannot answer that: lead 4 can
   still be scraping while lead 1 is already emailed. */
.lead__pips {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--s-1);
}
.pip {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--c-idle-soft);
  transition: background var(--m-base) var(--m-ease);
}
.pip[data-state="done"]   { background: var(--c-ok); }
.pip[data-state="active"] { background: var(--c-primary); animation: pip-pulse 1.6s var(--m-ease) infinite; }
.pip[data-state="drop"]   { background: var(--c-drop); }
@keyframes pip-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}

/* ---- progress ------------------------------------------------------------ */
.lead__progress { display: flex; flex-direction: column; gap: var(--s-1); }
.lead__progress[hidden] { display: none; }

.lead__bar {
  position: relative;
  overflow: hidden;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--c-idle-soft);
}
.lead__barfill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--c-primary);
  transition: width var(--m-base) var(--m-ease);
}
/* Until the crawler knows how many pages there are, a bar parked at 0% for four
   minutes reads as broken. This one reads as working. */
.lead[data-prog="indeterminate"] .lead__bar::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 30%;
  border-radius: var(--r-pill);
  background: var(--c-primary);
  animation: rail-sweep 1.4s var(--m-ease) infinite;
}

.lead__progmeta {
  font-size: var(--t-xs);
  color: var(--c-fg-muted);
  gap: var(--s-1) var(--s-3);
}
.lead__pages { color: var(--c-fg); }
.lead__elapsed { color: var(--c-fg-muted); }
.lead__beat[hidden], .lead__note[hidden] { display: none; }
/* A scrape that has said nothing for two minutes is not obviously alive. */
.lead__beat--stale { color: var(--c-warn-ink); font-weight: var(--fw-semi); }

/* ---- sections ------------------------------------------------------------ */
.lead__sec {
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface-2);
}
.lead__sec[hidden] { display: none; }

.lead__sectop {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  min-height: 40px;
  cursor: pointer;
  list-style: none;
  border-radius: var(--r-md);
  user-select: none;
}
.lead__sectop::-webkit-details-marker { display: none; }
.lead__sectop:hover { background: var(--c-primary-soft); }

/* A disclosure triangle drawn from a border, so no icon font and no emoji. */
.lead__sectop::before {
  content: '';
  flex: none;
  width: 0;
  height: 0;
  border-left: 5px solid var(--c-fg-faint);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform var(--m-fast) var(--m-ease);
}
.lead__sec[open] > .lead__sectop::before { transform: rotate(90deg); }

.lead__sectitle {
  font-size: var(--t-xs);
  font-weight: var(--fw-semi);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-fg-muted);
}
.lead__seccount { margin-left: auto; }

.lead__secbody {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: 0 var(--s-3) var(--s-3);
}

.lead__error {
  margin: 0;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: var(--c-danger-soft);
  color: var(--c-danger-ink);
  font-size: var(--t-sm);
}
.lead__error[hidden] { display: none; }

/* ---- contacts ------------------------------------------------------------ */
.contact {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-1) var(--s-3);
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--c-border);
  font-size: var(--t-sm);
}
.contact:last-child { border-bottom: 0; padding-bottom: 0; }
.contact__name { font-weight: var(--fw-semi); min-width: 6ch; }
.contact__email { color: var(--c-primary); }
.contact__phone { color: var(--c-fg-muted); }
.contact__email[hidden], .contact__phone[hidden], .contact__src[hidden] { display: none; }

/* ---------------------------------------------------------------------------
   THE DROP, phase 1: the strike, in place.
   ---------------------------------------------------------------------------
   The card must visibly change BEFORE it travels, or the eye never catches
   which lead went. The rule is drawn with a pseudo-element rather than
   text-decoration so it can be animated across the name.
--------------------------------------------------------------------------- */
.lead--dropping {
  background: var(--c-drop-soft);
  border-left-color: var(--c-drop);
  opacity: .85;
}
.lead--dropping .lead__name::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 55%;
  height: 2px;
  background: var(--c-drop);
  transform-origin: left center;
  animation: strike var(--m-base) var(--m-ease) forwards;
}
@keyframes strike {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* ---------------------------------------------------------------------------
   The dropped column
--------------------------------------------------------------------------- */
.drop {
  padding: var(--s-2);
  background: var(--c-drop-soft);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}
.drop__summary {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  cursor: pointer;
  list-style: none;
  min-height: 36px;
}
.drop__summary::-webkit-details-marker { display: none; }

.drop__top { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; }
.drop__ord { font-size: var(--t-xs); color: var(--c-fg-faint); flex: none; }
/* Struck through permanently. This is the state, not the animation. */
.drop__name {
  font-size: var(--t-base);
  font-weight: var(--fw-medium);
  color: var(--c-fg-muted);
  text-decoration: line-through;
  text-decoration-color: var(--c-drop);
  text-decoration-thickness: 1px;
}
.drop__bot { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.drop__time { font-size: var(--t-xs); }

.drop__detail {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  margin-top: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--c-border);
  font-size: var(--t-xs);
}
.drop__row { display: flex; gap: var(--s-2); }
.drop__row[hidden] { display: none; }
.drop__key { flex: none; width: 8ch; color: var(--c-fg-faint); }
.drop__val { min-width: 0; color: var(--c-fg-muted); }
.drop__row--err .drop__val { color: var(--c-danger-ink); }

.drop:hover { border-color: var(--c-border-strong); }
.drop[open] { background: var(--c-surface); }

/* Both pane heads carry a variable number of filter chips: one per drop reason
   that has actually happened, and one per lead filter. Neither fits on one line
   in a 300px column or on a 390px phone, and .pane__filters does not wrap on its
   own, so the last chip would be clipped off the right edge and the document
   would pick up a horizontal overflow. They wrap instead. */
.pane--dropped .pane__head,
.pane--leads .pane__head { flex-wrap: wrap; }
#dropped-filters,
#leads-toolbar { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
#dropped-filters[hidden] { display: none; }

.dropped-empty {
  padding: var(--s-4) var(--s-3);
  font-size: var(--t-sm);
  color: var(--c-fg-muted);
  text-align: center;
}
.dropped-empty p { margin-bottom: var(--s-1); }

/* ---------------------------------------------------------------------------
   THE DROP, phase 2: the flight.
   ---------------------------------------------------------------------------
   leadStream.js lifts the real card to position:fixed for the travel, because
   .pane is overflow-y:auto and would otherwise clip the whole animation at the
   column's edge. The spacer holds its slot open so the column does not collapse
   and re-expand underneath it.
--------------------------------------------------------------------------- */
.drop--flying {
  z-index: var(--z-modal);
  box-shadow: var(--sh-3);
  pointer-events: none;
  background: var(--c-surface);
  border-color: var(--c-drop);
}
.drop-spacer { flex: none; }

/* ---- narrow -------------------------------------------------------------- */
@media (max-width: 1023px) {
  .lead { padding: var(--s-3); gap: var(--s-2); }
  .lead__head { grid-template-columns: auto minmax(0, 1fr); }
  .lead__statecol {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .lead__name { font-size: var(--t-md); }
  .lead__sectop { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .lead { animation: none; }
  .pip[data-state="active"] { animation: none; }
  .lead[data-prog="indeterminate"] .lead__bar::after { animation: none; width: 100%; opacity: .35; }
  /* The strike still happens, it just does not sweep. The information survives;
     only the motion goes. */
  .lead--dropping .lead__name::after { animation: none; transform: scaleX(1); }
}
