/* Leads page: masthead + summary tiles above the kanban board. Mirrors the
   customers page header; the page scrolls and the board keeps its own height. */
@scope (.leads-page) {
  :scope {
    --_border: var(--color-border-muted);
    --_ink: var(--color-text-heading);
    --_surface: var(--color-surface);
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .leads-page__masthead {
    flex-shrink: 0;
    padding-block: var(--space-lg) 0;
    border-bottom: 1px solid var(--_border);
  }

  .leads-page__eyebrow,
  .leads-page__metric-label {
    color: var(--color-text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: var(--tracking-widest);
    text-transform: uppercase;
  }

  .leads-page__title {
    margin-top: var(--space-xs);
    color: var(--_ink);
    font-size: clamp(var(--text-heading-2), 3vw, var(--text-heading-1));
    font-weight: var(--font-semibold);
  }

  .leads-page__thesis {
    max-inline-size: 44rem;
    margin-top: var(--space-sm);
    color: var(--color-text-secondary);
    font-size: var(--text-body);
  }

  .leads-page__summary {
    display: grid;
    flex-shrink: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--_border);
    border-radius: var(--radius-xl);
    background: var(--_surface);
    box-shadow: var(--shadow-xs);
  }

  .leads-page__metric {
    display: grid;
    align-content: start;
    gap: var(--space-xs);
    min-inline-size: 0;
    padding: var(--space-lg);
    border-inline-end: 1px solid var(--_border);
  }

  .leads-page__metric:last-child {
    border-inline-end: 0;
  }

  .leads-page__metric--pipeline {
    background: var(--color-primary-muted);
  }

  .leads-page__metric-value {
    overflow: hidden;
    color: var(--_ink);
    font-family: var(--font-mono);
    font-size: var(--text-heading-3);
    font-variant-numeric: tabular-nums;
    letter-spacing: var(--tracking-tighter);
    line-height: var(--leading-tight);
    text-overflow: ellipsis;
  }

  .leads-page__metric-detail {
    color: var(--color-text-muted);
    font-size: var(--text-caption);
  }

  .toolbar.leads-page__toolbar {
    padding-bottom: 0;
  }

  .leads-page__new {
    white-space: nowrap;
  }

  /* The page is the only vertical scroll: columns grow with their cards and the
     stage rail sticks to the top. Focus mode below brings back inner scrolling. */
  .board-shell {
    flex: none;
  }

  .leads-page__focus {
    margin-inline-start: auto;
    white-space: nowrap;
  }

  .leads-page__focus-enter,
  .leads-page__focus-leave {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);

    .icon {
      inline-size: 1.25rem;
      block-size: 1.25rem;
      fill: currentColor;
    }
  }

  .leads-page__focus-leave {
    display: none;
  }

  /* Focus mode (same controller as the agenda): only the toolbar and the board
     stay, and the board takes the whole viewport instead of a fixed height. */
  :scope[data-focused] {
    overflow-y: hidden;

    .leads-page__masthead,
    .leads-page__summary {
      display: none;
    }

    .leads-page__focus-enter {
      display: none;
    }

    .leads-page__focus-leave {
      display: inline-flex;
    }

    .board-shell {
      flex: 1;
      height: auto;
      min-height: 0;
    }
  }

  /* Loading state: Turbo marks the submitting form `aria-busy` while the search
     or filters reload the page. The tiles and board fade after a short delay (no
     flicker on fast responses) and ignore clicks until the new result lands. */
  :scope:has(:is(#leads-search-form, #leads-filter-form)[aria-busy="true"]) {
    cursor: progress;

    .leads-page__summary,
    .board {
      pointer-events: none;
      animation: leads-page-refresh 0.2s ease-out 0.15s both;
    }
  }

  @container (width < 48rem) {
    .leads-page__summary {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .leads-page__metric:nth-child(2) {
      border-inline-end: 0;
    }

    .leads-page__metric:nth-child(-n + 2) {
      border-bottom: 1px solid var(--_border);
    }
  }

  @container (width < 28rem) {
    .leads-page__summary {
      grid-template-columns: 1fr;
    }

    .leads-page__metric {
      border-inline-end: 0;
      border-bottom: 1px solid var(--_border);
    }

    .leads-page__metric:last-child {
      border-bottom: 0;
    }
  }

  @media (prefers-contrast: more) {
    .leads-page__summary {
      border-width: 2px;
    }
  }
}

@keyframes leads-page-refresh {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  @keyframes leads-page-refresh {
    from { opacity: 0.45; }
    to { opacity: 0.45; }
  }
}
