/* ================================================
   COHORT SUMMARY — the aggregates above the list:
   completion funnel, score scatter plot + role-bar
   control, stat tiles, band distribution bars.

   Split out of eval-cohort.css. Band colours live in
   eval-cohort-bands.css (shared with the row chips).
   ================================================ */

@layer components {
  .cohort-root {
    .cohort-summary {
      display: flex;
      flex-direction: column;
      gap: var(--space-md);
      padding: var(--space-lg);
      border-radius: var(--radius-lg);
      margin-block-end: var(--space-md);
    }

    .cohort-funnel {
      display: flex;
      flex-wrap: wrap;
      align-items: stretch;
      gap: var(--space-sm);
      margin: 0;
      padding: 0;
      list-style: none;

      .funnel-step {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-4xs);
        /* Kill the app-wide adjacent-sibling stack margin (base.css owl) — it
           lands only on steps 2..n and shoves them ~5px below Invited. This row
           spaces horizontally via the parent's `gap`, so no margin is wanted. */
        margin: 0;
        flex: 1 1 0;
        min-width: 4.5rem;
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--radius-md);

        .funnel-count {
          font-size: var(--fs-large);
          font-weight: var(--fw-bold);
          line-height: 1;
        }

        .funnel-label {
          font-size: var(--fs-xsmall);
          font-weight: var(--fw-medium);
          text-transform: uppercase;
          letter-spacing: 0.04em;
        }
      }
    }

    /* ---- Cohort distribution strip ---- */
    .cohort-plot-stage {
      position: relative;
    }

    .cohort-plot {
      inline-size: 100%;
      block-size: auto;
      display: block;
    }

    /* The role bar is a handle dragged along the plot; touch-action:none so a
       touch-drag moves the bar instead of scrolling the page. */
    .cohort-bar-handle {
      cursor: grab;
      touch-action: none;

      &:active {
        cursor: grabbing;
      }
    }

    /* Dots fade as they cross behind the bar; smooth the state change. */
    .cohort-dot {
      transition: fill-opacity 0.12s ease;
    }

    /* ---- Interactive role-bar control ---- */
    .cohort-bar-control {
      display: flex;
      flex-direction: column;
      gap: var(--space-2xs);
      margin-block-start: var(--space-sm);
    }

    .cohort-bar-readout {
      font-size: var(--fs-small);
      font-weight: var(--fw-medium);
    }

    .cohort-bar-actions {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-2xs);
    }

    .cohort-bar-btn {
      padding: var(--space-4xs) var(--space-sm);
      border-radius: var(--radius-sm);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      cursor: pointer;

      &:disabled {
        cursor: not-allowed;
      }
    }

    .cohort-bar-status {
      font-size: var(--fs-xsmall);
      min-block-size: 1rem;
    }

    /* ---- Cohort summary stat tiles ---- */
    .cohort-stats {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: var(--space-sm);

      .cohort-stat {
        display: flex;
        flex-direction: column;
        gap: var(--space-4xs);
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--radius-md);

        .cohort-stat-value {
          font-size: var(--fs-large);
          font-weight: var(--fw-bold);
          line-height: 1.1;
        }

        .cohort-stat-sub {
          font-size: var(--fs-xxsmall);
        }

        .cohort-stat-label {
          font-size: var(--fs-xsmall);
          font-weight: var(--fw-medium);
          text-transform: uppercase;
          letter-spacing: 0.03em;
        }
      }
    }

    .band-distribution {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-xs);

      .band-bar {
        display: inline-flex;
        align-items: baseline;
        gap: var(--space-2xs);
        padding: var(--space-2xs) var(--space-sm);
        border-radius: var(--radius-pill);

        .band-bar-count {
          font-size: var(--fs-small);
          font-weight: var(--fw-bold);
        }

        .band-bar-label {
          font-size: var(--fs-xsmall);
          font-weight: var(--fw-medium);
        }
      }
    }

    .cohort-note {
      margin: 0;
      font-size: var(--fs-xsmall);
      line-height: 1.5;
    }

    /* ---- Bulk action bar ---- */
  }
}

@layer theme {
  .cohort-root {
    .cohort-summary {
      background: light-dark(oklch(0% 0 0 / 0.02), oklch(100% 0 0 / 0.03));
      border: 1px solid var(--border-subtle);
    }

    .cohort-funnel .funnel-step {
      background: light-dark(oklch(0% 0 0 / 0.03), oklch(100% 0 0 / 0.04));
      color: var(--text-primary);

      .funnel-label {
        color: var(--text-secondary);
      }

      &.is-terminal {
        background: oklch(from var(--accent-primary) l c h / 0.1);
        color: var(--accent-primary);

        .funnel-label {
          color: var(--accent-primary);
        }
      }
    }

    .cohort-note {
      color: var(--text-secondary);
    }

    .cohort-stats .cohort-stat {
      background: light-dark(oklch(0% 0 0 / 0.03), oklch(100% 0 0 / 0.04));

      .cohort-stat-sub,
      .cohort-stat-label {
        color: var(--text-secondary);
      }
    }

    .cohort-stat--ahead .cohort-stat-value {
      color: var(--color-success);
    }

    .cohort-stat--behind .cohort-stat-value {
      color: var(--color-error);
    }

    .cohort-stat--most .cohort-stat-value {
      color: var(--text-primary);
    }

    /* ---- Interactive role-bar control ---- */
    .cohort-bar-handle:focus-visible {
      outline: none;

      /* The handle group is focusable (role="slider"); mark focus on the knob
         itself rather than boxing the whole tall handle. */
      .cohort-bar-knob rect {
        stroke: var(--accent-primary);
        stroke-width: 2;
      }
    }

    .cohort-bar-readout {
      color: var(--text-primary);
    }

    .cohort-bar-btn {
      background: transparent;
      border: 1px solid var(--border-muted);
      color: var(--text-secondary);

      &:hover:not(:disabled) {
        border-color: var(--accent-primary);
        color: var(--accent-primary);
      }

      &:disabled {
        opacity: 0.55;
      }
    }

    .cohort-bar-btn--primary {
      border-color: var(--accent-primary);
      background: var(--accent-primary);
      color: var(--surface-base);

      &:hover:not(:disabled) {
        color: var(--surface-base);
        opacity: 0.9;
      }
    }

    .cohort-bar-status {
      color: var(--text-secondary);
    }

    /* Disposition buttons — outline that fills on hover. Pseudo-classes nest
       fine under `&`; the coloured variants are flat (see the note above). */
  }
}
