/* ============================================
   CANDIDATE INTELLIGENCE PAGE
   ============================================
   Convention (matches the rest of the per-page CSS in this project):
   - @layer components: structural rules only — sizing, positioning, grid/
     flex, padding/margin, transitions, font-size/weight, border-radius
     (NOT border-color).
   - @layer theme: all color / surface / border-color / background /
     box-shadow / text-color rules. Theme is later in the cascade than
     components (see base.css `@layer reset, base, components, utilities,
     theme, overrides`), so dark-mode and other palette overrides win
     without selector specificity wars.
   ============================================ */

/* --- COMPONENTS --- */
@layer components {
  .candidate-intelligence-page {
    position: relative;
    padding-block: var(--space-xl);
    overflow: hidden;
    display: block;

    /* Tab strip under the page header. Active tab inherits --accent-primary
       underline; inactive tabs use muted text. Matches the tab pattern
       used on the evaluation detail page. */
    .ci-tabs {
      display: flex;
      gap: var(--space-sm);
      margin-block: var(--space-lg) var(--space-lg);
    }

    /* Sticky ingest-progress banner. Sits above the tab strip so the
       indicator stays visible regardless of which tab the user clicks
       through to. Hidden by default; JS toggles the hidden attribute
       based on sessionStorage state. Native <details>/<summary> drives
       the expand/collapse — no JS aria plumbing. Color tokens live in
       the theme layer below. */
    .ci-ingest-banner {
      position: sticky;
      inset-block-start: 0;
      z-index: 1;
      padding: var(--space-sm) var(--space-md);
      margin-block-start: var(--space-md);
      border-radius: var(--radius-md);
      font-size: var(--fs-small);

      &[hidden] {
        display: none;
      }

      .ci-ingest-banner-summary {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
        cursor: pointer;
        list-style: none;
      }

      .ci-ingest-banner-summary::-webkit-details-marker {
        display: none;
      }

      .ci-ingest-banner-summary::marker {
        content: '';
      }

      .ci-ingest-banner-spinner {
        inline-size: 14px;
        block-size: 14px;
        border-radius: 50%;
        border: 2px solid transparent;
        animation: ci-spin var(--time-animation) linear infinite;
      }

      .ci-ingest-banner-text {
        flex: 1;
        font-weight: var(--fw-medium);
      }

      .ci-ingest-banner-list {
        margin: var(--space-xs) 0 0;
        padding: 0;
        list-style: none;
        display: flex;
        flex-direction: column;
        gap: var(--space-3xs);
      }

      .ci-ingest-banner-item {
        display: flex;
        align-items: center;
        gap: var(--space-xs);
        padding: var(--space-2xs) var(--space-xs);
        border-radius: var(--radius-sm);
        font-size: var(--fs-xsmall);

        .ci-ingest-banner-item-name {
          flex: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }

    .ci-tab {
      padding: var(--space-sm) var(--space-md);
      font-size: var(--fs-small);
      font-weight: var(--fw-medium);
      text-decoration: none;
      margin-block-end: -1px;
      transition:
        color var(--time-fast) var(--ease-standard),
        border-color var(--time-fast) var(--ease-standard);
    }

    .ci-panel {
      min-block-size: 40vh;
    }

    /* Stub panel — present only until each tab's real content lands. */
    .ci-empty-panel {
      padding: var(--space-xl);
      border-radius: var(--wire-radius);
      text-align: center;

      h2 {
        font-size: var(--fs-large);
        font-weight: var(--fw-semibold);
        margin-block-end: var(--space-sm);
      }
    }

    .ci-empty-hint {
      font-size: var(--fs-small);
    }

    /* ── Search view ───────────────────── */
    .ci-search-panel {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
    }

    .ci-search-form {
      display: flex;
      gap: var(--space-sm);
      align-items: stretch;
    }

    /* Page-level search lives above the tab strip so it's reachable
       from any tab. Full-width within the page column, sits just under
       the header with enough gap to read as its own block. */
    .ci-search-form--page {
      margin-block: var(--space-md) var(--space-lg);

      /* Pending state kicks in on submit (GET nav) so the user gets
         feedback while the server runs planner + Qdrant. The input dims
         and the button disables with a spinner alongside its label. */
      &[data-state='pending'] .ci-search-input {
        opacity: 0.6;
        pointer-events: none;
      }

      &[data-state='pending'] button[type='submit'] {
        position: relative;
        padding-inline-start: calc(var(--space-md) + 1.2em);
        cursor: wait;
        opacity: 0.8;

        &::before {
          content: '';
          position: absolute;
          inset-inline-start: var(--space-sm);
          inset-block-start: 50%;
          inline-size: 0.9em;
          block-size: 0.9em;
          margin-block-start: -0.45em;
          border-radius: 50%;
          animation: ci-spin var(--time-animation) linear infinite;
        }
      }
    }

    .ci-search-input {
      flex: 1;
      padding: var(--space-sm) var(--space-md);
      border-radius: var(--wire-radius);
      font-size: var(--fs-body);
      font-family: inherit;
      transition: border-color var(--time-fast) var(--ease-standard);
    }

    .ci-search-intro {
      padding: var(--space-xl);
      border-radius: var(--radius-md);

      h2 {
        margin: 0 0 var(--space-sm) 0;
        font-size: var(--fs-large);
      }

      p {
        margin: 0;
        font-size: var(--fs-small);
        line-height: 1.55;
      }
    }

    .ci-search-meta {
      display: flex;
      gap: var(--space-md);
      align-items: baseline;
      font-size: var(--fs-xsmall);
    }

    .ci-search-mode {
      padding: var(--space-3xs) var(--space-sm);
      border-radius: var(--radius-pill);
      font-weight: var(--fw-medium);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    .ci-filter-chips {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--space-xs);
      padding: var(--space-md);
      border-radius: var(--radius-md);

      .ci-filter-chips-label {
        font-size: var(--fs-xsmall);
        font-weight: var(--fw-semibold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-inline-end: var(--space-xs);
      }

      .ci-filter-chip {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2xs);
        padding: var(--space-2xs) var(--space-xs) var(--space-2xs) var(--space-sm);
        border-radius: var(--radius-pill);
        font-size: var(--fs-xsmall);

        .ci-filter-chip-kind {
          font-weight: var(--fw-medium);
          margin-inline-end: var(--space-3xs);
        }

        .ci-filter-chip-value {
          font-weight: var(--fw-semibold);
        }

        .ci-filter-chip-remove {
          inline-size: 20px;
          block-size: 20px;
          border-radius: 50%;
          font-size: var(--fs-small);
          line-height: 1;
          cursor: pointer;
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 0;
          transition:
            background var(--time-fast),
            color var(--time-fast);
        }
      }

      .ci-filter-add {
        padding: var(--space-2xs) var(--space-sm);
        border-radius: var(--radius-pill);
        font-size: var(--fs-xsmall);
        cursor: pointer;
        transition:
          border-color var(--time-fast),
          color var(--time-fast);
      }
    }

    .ci-filter-editor {
      padding: var(--space-md);
      border-radius: var(--radius-md);

      .ci-filter-editor-row {
        display: flex;
        gap: var(--space-sm);
        align-items: stretch;
      }

      .ci-filter-type-select,
      .ci-filter-value-input {
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--wire-radius);
        font-size: var(--fs-small);
        font-family: inherit;
      }

      .ci-filter-value-input {
        flex: 1;
      }
    }

    /* ── Ingest panel (unified single + bulk) ───────────────────── */
    .ci-ingest-panel {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
      max-inline-size: 720px;
      margin-inline: auto;
    }

    /* Recruiter-notes block sits between the dropzone and the per-file
       progress list. Hidden by JS when the user picks more than one
       file — notes are a single-candidate concept. */
    .ci-ingest-notes {
      display: flex;
      flex-direction: column;
      gap: var(--space-xs);

      &[hidden] {
        display: none;
      }

      label {
        font-size: var(--fs-xsmall);
        font-weight: var(--fw-semibold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
      }

      textarea {
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--wire-radius);
        font-size: var(--fs-small);
        font-family: inherit;
        resize: vertical;
        min-block-size: 4em;
      }
    }

    .ci-ingest-intro {
      padding: var(--space-lg);
      border-radius: var(--radius-md);

      h2 {
        margin: 0 0 var(--space-sm) 0;
        font-size: var(--fs-large);
      }

      p {
        margin: 0;
        font-size: var(--fs-small);
        line-height: 1.55;
      }
    }

    /* ── Bulk dropzone ───────────────────── */
    .ci-bulk-dropzone {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: var(--space-xl);
      border-radius: var(--radius-md);
      transition: border-color var(--time-fast);

      .ci-bulk-dropzone-label {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-sm);
        cursor: pointer;

        .ci-bulk-dropzone-primary {
          font-size: var(--fs-body);
          font-weight: var(--fw-medium);
        }

        .ci-bulk-dropzone-secondary {
          font-size: var(--fs-xsmall);
        }
      }
    }

    .ci-bulk-list {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: var(--space-xs);

      .ci-bulk-item {
        display: grid;
        grid-template-columns: 1fr auto auto;
        gap: var(--space-md);
        align-items: center;
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--wire-radius);
        font-size: var(--fs-small);

        .ci-bulk-item-name {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .ci-bulk-item-status {
          font-size: var(--fs-xsmall);
        }

        .ci-bulk-item-retry {
          padding: var(--space-3xs) var(--space-sm);
          border-radius: var(--radius-pill);
          font-size: var(--fs-xsmall);
          cursor: pointer;
        }
      }
    }

    .ci-bulk-summary {
      font-size: var(--fs-small);
      text-align: end;
    }

    /* ── Intelligence tab — corpus analytics ───────────────────── */
    .ci-intelligence-panel {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
    }

    .ci-stats-total {
      display: flex;
      align-items: baseline;
      gap: var(--space-sm);
      padding: var(--space-lg);
      border-radius: var(--radius-md);

      .ci-stats-total-value {
        font-size: var(--fs-xxl);
        font-weight: var(--fw-semibold);
        font-family: var(--font-display);
      }

      .ci-stats-total-label {
        font-size: var(--fs-small);
      }
    }

    .ci-stats-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
      gap: var(--space-md);

      .ci-stats-card {
        padding: var(--space-lg);
        border-radius: var(--radius-md);

        &--wide {
          grid-column: 1 / -1;
        }

        h3 {
          font-size: var(--fs-small);
          font-weight: var(--fw-semibold);
          text-transform: uppercase;
          letter-spacing: 0.05em;
          margin: 0 0 var(--space-sm) 0;
        }

        .ci-stats-list {
          list-style: none;
          margin: 0;
          padding: 0;
          display: flex;
          flex-direction: column;
          gap: var(--space-xs);

          .ci-stats-row {
            display: grid;
            grid-template-columns: 7em 1fr 3em;
            align-items: center;
            gap: var(--space-sm);
            font-size: var(--fs-small);

            .ci-stats-row-label {
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }

            .ci-stats-row-bar {
              block-size: 6px;
              border-radius: var(--radius-pill);
              overflow: hidden;

              .ci-stats-row-fill {
                block-size: 100%;
                border-radius: var(--radius-pill);
                transition: width var(--time-medium) var(--ease-out);
              }
            }

            .ci-stats-row-value {
              text-align: end;
              font-variant-numeric: tabular-nums;
            }
          }
        }
      }
    }

    /* ── Integrations tab ───────────────────── */
    .ci-integrations-panel {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
    }

    .ci-integrations-intro {
      padding: var(--space-lg);
      border-radius: var(--radius-md);

      h2 {
        margin: 0 0 var(--space-sm) 0;
      }

      p {
        margin: 0;
        font-size: var(--fs-small);
        line-height: 1.55;
      }
    }

    .ci-integrations-list {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: var(--space-md);
    }

    .ci-integration-card {
      display: flex;
      flex-direction: column;
      gap: var(--space-sm);
      padding: var(--space-lg);
      border-radius: var(--radius-md);

      h3 {
        margin: 0;
        font-size: var(--fs-body);
      }

      p {
        margin: 0;
        font-size: var(--fs-small);
        line-height: 1.5;
      }
    }

    .ci-integration-status {
      align-self: flex-start;
      padding: var(--space-3xs) var(--space-sm);
      border-radius: var(--radius-pill);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
    }
  }

  /* Ingest result panel — single-CV upload outcome view. Not scoped
     to .candidate-intelligence-page because it can also surface on
     the /candidate-intelligence/<id>/ingest sub-route. */
  .ci-ingest-result {
    padding: var(--space-xl);
    border-radius: var(--radius-md);
    text-align: center;

    h2 {
      margin: 0 0 var(--space-sm) 0;
      font-size: var(--fs-large);
    }

    p {
      font-size: var(--fs-small);
      line-height: 1.55;
    }
  }

  .ci-ingest-result-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
    margin-block-start: var(--space-md);
  }

  @keyframes ci-spin {
    to {
      transform: rotate(360deg);
    }
  }

  /* Visually-hidden text for screen readers — global utility. */
  .sr-only {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* ============================================
     CANDIDATE INTELLIGENCE DETAIL PAGE
     ============================================ */

  .candidate-intelligence-detail-page {
    position: relative;
    padding-block: var(--space-lg) calc(var(--space-xl) * 2);
    display: block;

    .back-link {
      display: inline-flex;
      align-items: center;
      gap: var(--space-xs);
      font-size: var(--fs-small);
      text-decoration: none;
      transition: opacity var(--time-fast) var(--ease-standard);
      position: relative;
      z-index: 1;
    }

    /* Identity card — mirrors the verdict-card shape used by the
       evaluation detail page so the two feel like siblings.
       NB: no `overflow: hidden` here — it would clip the inferred-field
       tooltips (which escape their row to overlay nearby content). The
       only child that needed clipping was the full-bleed top strip, so
       that one rounds its own top corners instead (see .ci-detail-strip). */
    .ci-detail-card {
      border-radius: var(--radius-md);
      margin-block: var(--space-lg);
      position: relative;
      z-index: 1;
    }

    .ci-detail-strip {
      block-size: 4px;
      inline-size: 100%;
      /* Match the card's rounded top corners directly, rather than
         relying on the card to clip us — see the card comment above. */
      border-start-start-radius: var(--radius-md);
      border-start-end-radius: var(--radius-md);
    }

    .ci-detail-body {
      padding: var(--space-lg) var(--space-xl);
    }

    .ci-detail-top {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: var(--space-lg);
    }

    .ci-detail-identity {
      display: flex;
      align-items: flex-start;
      gap: var(--space-md);
      min-inline-size: 0;
      flex: 1;

      h1 {
        font-size: var(--fs-xl);
        margin: 0;
      }
    }

    .ci-detail-email {
      font-size: var(--fs-small);
      margin: 0;
    }

    .ci-detail-headline {
      font-size: var(--fs-small);
      margin-block-start: var(--space-xs);
    }

    .avatar--large {
      inline-size: 64px;
      block-size: 64px;
      font-size: var(--fs-medium);
    }

    .ci-detail-badges {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-xs);
      align-items: flex-start;
    }

    /* Base pill shape for badges on the detail page. Duplicated from
       the list-page .badge rule because both rules are nested under
       page wrappers and this page uses a different one. Variant
       colors (.badge--mid, .badge--staff, etc.) live in the theme
       layer below. Cleaning up the per-page-wrapper duplication for
       badges would be its own CL. */
    .badge {
      display: inline-flex;
      align-items: center;
      padding: var(--space-3xs) var(--space-sm);
      border-radius: var(--radius-pill);
      font-size: var(--fs-tiny);
      font-weight: var(--fw-medium);
      white-space: nowrap;
    }

    .ci-detail-summary {
      margin-block-start: var(--space-md);
      font-size: var(--fs-body);
      line-height: 1.55;
    }

    /* Three-panel snapshot row */
    .ci-detail-snapshot {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
      gap: var(--space-md);
      margin-block-end: var(--space-xl);
    }

    .ci-snapshot-panel {
      padding: var(--space-lg);
      border-radius: var(--radius-md);

      h3 {
        font-size: var(--fs-body);
        font-weight: var(--fw-semibold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin: 0 0 var(--space-md) 0;
      }
    }

    .ci-kv {
      display: grid;
      grid-template-columns: auto 1fr;
      gap: var(--space-xs) var(--space-md);
      margin: 0;
      font-size: var(--fs-small);

      dd {
        margin: 0;
        text-align: start;
      }

      /* Hide empty rows entirely. The renderer emits an empty Node
         for the "—" sentinel (see fieldHtml + renderInflationAssessment
         in CandidateIntelligenceRenderer.fs) so dd becomes :empty,
         and we collapse both the dt label and the dd value via :has()
         instead of rendering em-dash placeholder noise on every
         missing field. */
      dd:empty,
      dt:has(+ dd:empty) {
        display: none;
      }
    }

    /* One-line legend explaining the asterisk marker. Sits between
       the identity card and the snapshot grid; only rendered when at
       least one field on the candidate is inferred. */
    .ci-inference-legend {
      margin-block: calc(-1 * var(--space-md)) var(--space-md);
      padding: var(--space-sm) var(--space-md);
      border-radius: var(--radius-md);
      font-size: var(--fs-small);
    }

    /* Inferred-field marker: an asterisk after a value that was
       inferred by the LLM rather than extracted from the CV. Hovering
       or focusing the marker reveals a tooltip popover carrying the
       LLM's reasoning + confidence so a recruiter can inspect the
       rationale — replacing the old native `title`, which rendered
       unstyled and was easy to miss. */
    .ci-inferred-field {
      display: inline-flex;
      align-items: baseline;
      gap: 0.15em;

      .ci-inferred-marker {
        position: relative;
        cursor: help;
        font-weight: var(--fw-semibold);

        .ci-inferred-tooltip {
          position: absolute;
          /* Below the marker: the card no longer clips (see
             .ci-detail-card), so dropping downward keeps the tooltip clear
             of the viewport's top edge for fields in the first card. */
          inset-block-start: calc(100% + var(--space-2xs));
          inset-inline-start: 0;
          z-index: 30;
          inline-size: max-content;
          max-inline-size: 20rem;
          padding: var(--space-xs) var(--space-sm);
          border-radius: var(--radius-sm);
          font-size: var(--fs-small);
          font-weight: var(--fw-regular);
          line-height: 1.45;
          text-align: start;
          white-space: normal;
          opacity: 0;
          visibility: hidden;
          transition: opacity 0.12s ease;
          pointer-events: none;
        }

        /* Reveal on hover (mouse) and focus (keyboard / tab). */
        &:hover .ci-inferred-tooltip,
        &:focus-visible .ci-inferred-tooltip {
          opacity: 1;
          visibility: visible;
        }
      }
    }

    /* Inflation detector row. Inline-flex so the bucket label, the
       claimed-vs-evidence caption, and the inferred marker sit on one
       line. All color rules (label variants + caption neutral) live in
       the theme layer below; this block keeps structure only, per the
       components/theme split convention. */
    .ci-inflation {
      display: inline-flex;
      align-items: baseline;
      gap: var(--space-2xs);
      flex-wrap: wrap;

      .ci-inflation-label {
        font-weight: var(--fw-semibold);
      }

      .ci-inflation-caption {
        font-size: var(--fs-small);
      }
    }

    /* Section blocks */
    .ci-section {
      margin-block-end: var(--space-xl);

      /* Section title gets a small left accent bar so each section
         reads as a clear hierarchy step. Color lives in the theme
         layer below. */
      h2 {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
        font-size: var(--fs-large);
        font-weight: var(--fw-semibold);
        margin: 0 0 var(--space-md) 0;

        &::before {
          content: '';
          display: block;
          inline-size: 3px;
          block-size: 1em;
          border-radius: var(--radius-xs);
        }
      }

      h3 {
        font-size: var(--fs-small);
        font-weight: var(--fw-semibold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin: 0 0 var(--space-sm) 0;
      }

      &--dual {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--space-lg);

        @media (max-width: 640px) {
          grid-template-columns: 1fr;
        }
      }
    }

    .ci-skills-grid,
    .ci-chip-row {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-xs);
    }

    /* Experience timeline — a vertical rail with a dot per entry. */
    .ci-timeline {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
      padding-inline-start: var(--space-md);
    }

    .ci-experience-entry {
      position: relative;
      display: flex;
      gap: var(--space-md);

      .ci-experience-dot {
        position: absolute;
        inset-inline-start: calc(var(--space-md) * -1 - 5px);
        inset-block-start: 6px;
        inline-size: 10px;
        block-size: 10px;
        border-radius: 50%;
      }

      .ci-experience-body {
        flex: 1;
      }

      .ci-experience-header {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-sm);
      }

      .ci-experience-company {
        margin-inline-start: var(--space-xs);
        font-weight: var(--fw-regular);
      }

      .ci-experience-period {
        font-size: var(--fs-xsmall);
        font-variant-numeric: tabular-nums;
      }

      .ci-experience-summary {
        margin-block: var(--space-xs);
        font-size: var(--fs-small);
        line-height: 1.5;
      }
    }

    .ci-education-list {
      display: flex;
      flex-direction: column;
      gap: var(--space-xs);
      margin-block-start: var(--space-sm);
    }

    .ci-education-entry {
      display: grid;
      grid-template-columns: 1fr auto;
      align-items: baseline;
      gap: var(--space-xs);
      font-size: var(--fs-small);

      strong {
        grid-column: 1;
      }

      .ci-education-year {
        grid-column: 2;
        grid-row: 1;
        font-variant-numeric: tabular-nums;
      }
    }

    .ci-empty-inline {
      font-style: italic;
      font-size: var(--fs-small);
    }

    /* Audit strip at the very bottom of the page */
    .ci-audit {
      display: flex;
      gap: var(--space-lg);
      padding-block-start: var(--space-md);
      font-size: var(--fs-xsmall);
    }

    .secondary-link {
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }

    .ci-actions-cell {
      inline-size: 1%;
      white-space: nowrap;
      text-align: end;
    }

    .ci-delete-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      inline-size: 32px;
      block-size: 32px;
      padding: 0;
      border: none;
      border-radius: 8px;
      cursor: pointer;
      transition:
        background 0.15s ease-out,
        color 0.15s ease-out;

      /* Keyboard-only focus ring — a mouse click no longer leaves a
         lingering outline (the "border" reported in #120). */
      &:focus-visible {
        outline: 2px solid currentColor;
        outline-offset: 2px;
      }
    }
  }
}

/* --- THEME --- */
@layer theme {
  .candidate-intelligence-page {
    /* Inflation detector colors. Reuses the semantic color tokens
       from shared/css/base.css — no new colors introduced. The
       caption stays in the secondary text color so it doesn't fight
       the label for attention. Stretch deliberately uses warning
       (not error) because most legitimate founder / early-stage
       candidates land there. Mismatch is the stronger signal;
       Understated reads as informational, not alarming. */
    .ci-inflation-caption {
      color: var(--text-secondary);
    }
    .ci-inflation--aligned .ci-inflation-label {
      color: var(--color-success);
    }
    .ci-inflation--stretch .ci-inflation-label {
      color: var(--color-warning);
    }
    .ci-inflation--mismatch .ci-inflation-label {
      color: var(--color-error);
    }
    .ci-inflation--understated .ci-inflation-label {
      color: var(--color-info);
    }

    .ci-tabs {
      border-block-end: 1px solid var(--border-color);
    }

    .ci-tab {
      color: var(--text-secondary);
      border-block-end: 2px solid transparent;
    }

    .ci-ingest-banner {
      background: var(--surface-elevated);
      border: var(--wire-border);
      color: var(--text-primary);

      .ci-ingest-banner-spinner {
        border-block-start-color: var(--accent-primary);
        border-inline-end-color: var(--accent-primary);
      }

      .ci-ingest-banner-summary:hover .ci-ingest-banner-text {
        color: var(--text-secondary);
      }

      .ci-ingest-banner-item {
        background: oklch(from var(--glass-tint) l c h / 0.04);
        color: var(--text-secondary);

        .ci-ingest-banner-item-name {
          color: var(--text-primary);
        }
      }
    }

    .ci-tab:hover {
      color: var(--text-primary);
    }

    /* Active tab = body element carries data-tab=X AND the tab itself
       carries data-tab=X. Match the active one via attribute selector so
       the server-rendered active state lands without a JS round-trip. */
    &[data-tab='candidates'] .ci-tab[data-tab='candidates'],
    &[data-tab='ingest'] .ci-tab[data-tab='ingest'],
    &[data-tab='bulk'] .ci-tab[data-tab='bulk'],
    &[data-tab='intelligence'] .ci-tab[data-tab='intelligence'],
    &[data-tab='integrations'] .ci-tab[data-tab='integrations'] {
      color: var(--text-primary);
      border-block-end-color: var(--accent-primary);
    }

    .ci-empty-panel {
      border: var(--wire-border);
      background: var(--surface-elevated);

      h2 {
        color: var(--text-primary);
      }
    }

    .ci-empty-hint {
      color: var(--text-secondary);
    }

    /* Header count chip — mirrors the evaluations page's eval-count
       pattern. Shows "N candidates" or "Page N" depending on whether
       the backend reports a total. */
    .ci-count {
      padding: var(--space-xs) var(--space-sm);
      border-radius: var(--radius-pill);
      border: var(--wire-border);
      background: var(--surface-elevated);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      color: var(--text-secondary);
    }

    /* ── Candidates list ───────────────────── */
    .ci-candidates-list {
      display: flex;
      flex-direction: column;
      gap: var(--space-lg);
    }

    /* Identifier lookup form. Sits above the candidates table on the
       Candidates tab. Visually subordinate to the page-level
       natural-language search bar at the top of the page — same
       horizontal row pattern but smaller font + lighter weight.
       Color tokens live in the theme layer below. */
    .ci-lookup-form {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
      flex-wrap: wrap;
      font-size: var(--fs-small);
    }

    .ci-lookup-input {
      flex: 1;
      min-inline-size: 220px;
      padding: var(--space-2xs) var(--space-sm);
      border-radius: var(--wire-radius);
      font-size: var(--fs-small);
      font-family: inherit;
    }

    .ci-lookup-submit,
    .ci-lookup-clear {
      padding: var(--space-2xs) var(--space-md);
      font-size: var(--fs-small);
    }

    .ci-lookup-status {
      font-size: var(--fs-xsmall);

      &[data-state='idle']:empty {
        display: none;
      }
    }

    .ci-lookup-empty {
      padding: var(--space-md);
      text-align: center;
      font-size: var(--fs-small);
    }

    /* Corpus-at-a-glance strip — sits above the table on the
       Candidates tab so the dashboard signal isn't hidden behind a
       tab click. Single horizontal row that wraps cleanly on narrow
       viewports. */
    .ci-corpus-strip {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: var(--space-md) var(--space-lg);
      padding: var(--space-sm) var(--space-md);
      border: var(--wire-border);
      border-radius: var(--radius-md);
      background: var(--surface-elevated);
      font-size: var(--fs-small);
    }

    .ci-corpus-total strong {
      color: var(--accent-primary);
      font-weight: var(--fw-semibold);
      font-family: var(--font-display);
      font-size: var(--fs-large);
      margin-inline-end: var(--space-2xs);
    }

    .ci-corpus-group {
      display: inline-flex;
      align-items: center;
      gap: var(--space-xs);
      flex-wrap: wrap;
    }

    .ci-corpus-label {
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-semibold);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--text-secondary);
    }

    .ci-corpus-bucket {
      display: inline-flex;
      align-items: baseline;
      gap: var(--space-3xs);
      padding: var(--space-3xs) var(--space-xs);
      border-radius: var(--radius-sm);
      background: oklch(from var(--glass-tint) l c h / 0.06);
    }

    .ci-corpus-bucket-label {
      color: var(--text-primary);
    }

    .ci-corpus-bucket-count {
      color: var(--text-secondary);
      font-variant-numeric: tabular-nums;
      font-size: var(--fs-xsmall);
    }

    .ci-corpus-more {
      margin-inline-start: auto;
      color: var(--accent-primary);
      text-decoration: none;
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
    }

    .ci-corpus-more:hover {
      text-decoration: underline;
    }

    .ci-candidates-table {
      inline-size: 100%;
      border-collapse: separate;
      border-spacing: 0;
    }

    .ci-candidates-table thead th {
      text-align: start;
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-semibold);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--text-secondary);
      padding: var(--space-sm) var(--space-md);
      border-block-end: 1px solid var(--border-color);
    }

    .ci-candidates-table tbody td {
      padding: var(--space-md);
      border-block-end: 1px solid oklch(from var(--glass-tint) l c h / 0.06);
      vertical-align: middle;
      font-size: var(--fs-small);
    }

    .ci-candidate-row {
      cursor: pointer;
      transition: background var(--time-fast) var(--ease-standard);
    }

    .ci-candidate-row:hover {
      background: oklch(from var(--glass-tint) l c h / 0.04);
    }

    .candidate-cell {
      display: flex;
      align-items: center;
      gap: var(--space-sm);
      min-inline-size: 0;
    }

    .candidate-identity {
      display: flex;
      flex-direction: column;
      min-inline-size: 0;
    }

    .candidate-identity strong {
      font-weight: var(--fw-semibold);
      color: var(--text-primary);
    }

    .candidate-identity .email {
      font-size: var(--fs-xsmall);
      color: var(--text-secondary);
    }

    .avatar {
      inline-size: 36px;
      block-size: 36px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--accent-primary);
      color: white;
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-semibold);
      flex-shrink: 0;
    }

    .role-title {
      color: var(--text-primary);
      font-weight: var(--fw-medium);
    }

    .role-company {
      font-size: var(--fs-xsmall);
      color: var(--text-secondary);
    }

    .stage-badges {
      display: flex;
      gap: var(--space-2xs);
      flex-wrap: wrap;
    }

    /* Stage / industry badges. Colors come from status-* and accent
       tokens so they auto-adjust for dark/light theme. */
    .badge {
      display: inline-flex;
      align-items: center;
      padding: var(--space-3xs) var(--space-sm);
      border-radius: var(--radius-pill);
      font-size: var(--fs-tiny);
      font-weight: var(--fw-medium);
      white-space: nowrap;
    }

    .badge--early {
      background: oklch(from var(--color-success) l c h / 0.12);
      color: var(--color-success);
    }

    .badge--mid {
      background: oklch(from var(--accent-primary) l c h / 0.12);
      color: var(--accent-primary);
    }

    .badge--experienced {
      background: oklch(from var(--color-warning) l c h / 0.15);
      color: var(--color-warning);
    }

    .badge--leader {
      background: oklch(from var(--accent-warm) l c h / 0.15);
      color: var(--accent-warm);
    }

    .badge--executive {
      background: oklch(from var(--color-error) l c h / 0.14);
      color: var(--color-error);
    }

    /* Seniority-level badges — separate from the career-stage rules
       above. Card seniority comes through as mid/staff/senior/junior;
       reuse the existing accent palette so the colors stay coherent.
       Unmatched values fall back to the base .badge styling (pill
       shape, no specific color) — fine for future levels we haven't
       seen yet. */
    .badge--staff {
      background: oklch(from var(--accent-warm) l c h / 0.14);
      color: var(--accent-warm);
    }

    .badge--senior {
      background: oklch(from var(--color-success) l c h / 0.14);
      color: var(--color-success);
    }

    .badge--junior {
      background: oklch(from var(--glass-tint) l c h / 0.08);
      color: var(--text-secondary);
    }

    .badge--industry {
      background: oklch(from var(--glass-tint) l c h / 0.08);
      color: var(--text-secondary);
    }

    .badge--unknown {
      background: oklch(from var(--glass-tint) l c h / 0.06);
      color: var(--text-secondary);
    }

    /* Skill chips in the last column — truncated to 4 in the renderer
       so the row never wraps past ~2 lines. */
    .skills-cell {
      min-inline-size: 0;
    }

    /* Pill-shaped chips so each tag reads as a distinct UI element
       instead of melting into prose. The previous --space-3xs padding
       + --fs-tiny size + barely-visible background made dense skill
       rows look like wall-of-text. */
    .ci-skill-chip {
      display: inline-flex;
      align-items: center;
      padding: var(--space-2xs) var(--space-sm);
      border-radius: var(--radius-pill);
      border: var(--wire-border);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      line-height: 1.2;
      color: var(--text-secondary);
      background: oklch(from var(--glass-tint) l c h / 0.06);
    }

    .years-cell {
      color: var(--text-secondary);
      font-variant-numeric: tabular-nums;
      font-size: var(--fs-small);
    }

    .ci-delete-btn {
      background: transparent;
      color: var(--text-secondary);

      &:hover {
        background: light-dark(
          oklch(from var(--color-error) l c h / 0.1),
          oklch(from var(--color-error) l c h / 0.15)
        );
        color: var(--color-error);
      }

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

    /* Pagination (identical shape to evaluations, separate class so CI
       page's paginator evolves independently — e.g. adding filter
       persistence in the href via `&q=...`). */
    .pagination {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: var(--space-md);
      padding-block: var(--space-md);
    }

    .pagination-link {
      padding: var(--space-sm) var(--space-md);
      border-radius: var(--wire-radius);
      border: var(--wire-border);
      color: var(--text-primary);
      font-size: var(--fs-small);
      text-decoration: none;
      transition:
        background var(--time-fast) var(--ease-standard),
        border-color var(--time-fast) var(--ease-standard);
    }

    .pagination-link:hover {
      background: oklch(from var(--glass-tint) l c h / 0.06);
      border-color: var(--accent-primary);
    }

    .pagination-link--disabled {
      opacity: 0.4;
      pointer-events: none;
    }

    .pagination-info {
      font-size: var(--fs-small);
      color: var(--text-secondary);
    }

    /* Empty + error states. */
    .ci-empty-state,
    .ci-error-panel {
      padding: var(--space-xl);
      border: var(--wire-border);
      border-radius: var(--radius-md);
      background: var(--surface-elevated);
      text-align: center;
      color: var(--text-secondary);
    }

    .ci-empty-state svg {
      color: var(--text-secondary);
      margin-block-end: var(--space-sm);
    }

    .ci-error-panel {
      color: var(--color-error);
    }

    .ci-error-detail {
      font-size: var(--fs-xsmall);
      color: var(--text-secondary);
      margin-block-start: var(--space-xs);
    }
  }

  /* ============================================
       CANDIDATE INTELLIGENCE DETAIL PAGE
       ============================================ */

  .candidate-intelligence-detail-page {
    .back-link {
      color: var(--text-secondary);

      &:hover {
        color: var(--text-primary);
      }
    }

    .ci-detail-card {
      background: var(--surface-elevated);
      border: var(--wire-border);
    }

    .ci-detail-strip {
      background: linear-gradient(to right, var(--accent-primary), var(--accent-warm));
    }

    .ci-detail-email {
      color: var(--text-secondary);
    }

    .ci-detail-headline {
      color: var(--text-secondary);
    }

    .ci-detail-summary {
      color: var(--text-primary);
    }

    /* Pill chips on the detail page — same structural + theme look as
       the list-page chip rule (see .ci-skill-chip under
       .candidate-intelligence-page). Duplicated here because chip
       styling is mixed inside the page wrappers; cleaning up the
       components/theme split for this component would be its own CL. */
    .ci-skill-chip {
      display: inline-flex;
      align-items: center;
      padding: var(--space-2xs) var(--space-sm);
      border-radius: var(--radius-pill);
      border: var(--wire-border);
      font-size: var(--fs-xsmall);
      font-weight: var(--fw-medium);
      line-height: 1.2;
      color: var(--text-secondary);
      background: oklch(from var(--glass-tint) l c h / 0.06);
    }

    .ci-snapshot-panel {
      background: var(--surface-elevated);
      border: var(--wire-border);

      h3 {
        color: var(--text-secondary);
      }
    }

    .ci-kv {
      dt {
        color: var(--text-secondary);
      }

      dd {
        color: var(--text-primary);
      }
    }

    .ci-inferred-field .ci-inferred-marker {
      color: var(--accent-warm);

      .ci-inferred-tooltip {
        background: var(--surface-elevated);
        border: var(--wire-border);
        color: var(--text-primary);
        box-shadow: 0 4px 12px rgb(0 0 0 / 0.18);
      }
    }

    .ci-inference-legend {
      background: var(--surface-elevated);
      border: var(--wire-border);
      color: var(--text-secondary);

      .ci-inferred-marker {
        color: var(--accent-warm);
        font-weight: var(--fw-semibold);
      }
    }

    .ci-section {
      h2::before {
        background: var(--accent-primary);
      }

      h3 {
        color: var(--text-secondary);
      }
    }

    .ci-timeline {
      border-inline-start: 2px solid oklch(from var(--glass-tint) l c h / 0.08);
    }

    .ci-experience-entry {
      .ci-experience-dot {
        background: var(--text-secondary);
        border: 2px solid var(--surface-elevated);

        &--current {
          background: var(--accent-primary);
          box-shadow: 0 0 0 3px oklch(from var(--accent-primary) l c h / 0.2);
        }
      }

      .ci-experience-company {
        color: var(--text-secondary);
      }

      .ci-experience-period {
        color: var(--text-secondary);
      }

      .ci-experience-summary {
        color: var(--text-secondary);
      }
    }

    .ci-education-entry {
      .ci-education-year {
        color: var(--text-secondary);
      }
    }

    .ci-empty-inline {
      color: var(--text-secondary);
    }

    .ci-audit {
      border-block-start: 1px solid oklch(from var(--glass-tint) l c h / 0.06);
      color: var(--text-secondary);
    }

    .secondary-link {
      color: var(--accent-primary);
    }

    /* Badge variant colors — duplicated from list-page wrapper.
       Together with the .badge structural rule in the components
       layer above, this is what gives the seniority pill (Mid /
       Staff / Senior / Junior) its accent color on the detail page.
       Industry and unknown stay neutral. */
    .badge--early {
      background: oklch(from var(--color-success) l c h / 0.12);
      color: var(--color-success);
    }

    .badge--mid {
      background: oklch(from var(--accent-primary) l c h / 0.12);
      color: var(--accent-primary);
    }

    .badge--experienced {
      background: oklch(from var(--color-warning) l c h / 0.15);
      color: var(--color-warning);
    }

    .badge--leader {
      background: oklch(from var(--accent-warm) l c h / 0.15);
      color: var(--accent-warm);
    }

    .badge--executive {
      background: oklch(from var(--color-error) l c h / 0.14);
      color: var(--color-error);
    }

    .badge--staff {
      background: oklch(from var(--accent-warm) l c h / 0.14);
      color: var(--accent-warm);
    }

    .badge--senior {
      background: oklch(from var(--color-success) l c h / 0.14);
      color: var(--color-success);
    }

    .badge--junior {
      background: oklch(from var(--glass-tint) l c h / 0.08);
      color: var(--text-secondary);
    }

    .badge--industry {
      background: oklch(from var(--glass-tint) l c h / 0.08);
      color: var(--text-secondary);
    }

    .badge--unknown {
      background: oklch(from var(--glass-tint) l c h / 0.06);
      color: var(--text-secondary);
    }
  }

  .candidate-intelligence-page {
    /* ── Search view ───────────────────── */
    .ci-search-form--page[data-state='pending'] button[type='submit']::before {
      border: 2px solid currentColor;
      border-inline-end-color: transparent;
    }

    .ci-search-input {
      border: var(--wire-border);
      background: var(--surface-elevated);
      color: var(--text-primary);

      &:focus {
        border-color: var(--accent-primary);
        outline: none;
      }
    }

    .ci-lookup-input {
      border: var(--wire-border);
      background: var(--surface-elevated);
      color: var(--text-primary);

      &:focus {
        border-color: var(--accent-primary);
        outline: none;
      }
    }

    .ci-lookup-status {
      color: var(--text-secondary);

      &[data-state='error'] {
        color: var(--color-error);
      }
    }

    .ci-lookup-empty {
      color: var(--text-secondary);
    }

    .ci-search-intro {
      border: var(--wire-border);
      background: var(--surface-elevated);

      p {
        color: var(--text-secondary);
      }
    }

    .ci-search-meta {
      color: var(--text-secondary);
    }

    .ci-search-mode {
      background: oklch(from var(--accent-primary) l c h / 0.08);
      color: var(--accent-primary);
    }

    .ci-filter-chips {
      background: var(--surface-elevated);
      border: var(--wire-border);

      .ci-filter-chips-label {
        color: var(--text-secondary);
      }

      .ci-filter-chip {
        background: oklch(from var(--accent-primary) l c h / 0.08);
        color: var(--text-primary);

        .ci-filter-chip-kind {
          color: var(--text-secondary);
        }

        .ci-filter-chip-remove {
          background: transparent;
          border: none;
          color: var(--text-secondary);

          &:hover {
            background: oklch(from var(--color-error) l c h / 0.15);
            color: var(--color-error);
          }
        }
      }

      .ci-filter-add {
        border: 1px dashed oklch(from var(--text-secondary) l c h / 0.4);
        background: transparent;
        color: var(--text-secondary);

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

    .ci-filter-editor {
      background: oklch(from var(--glass-tint) l c h / 0.03);
      border: var(--wire-border);

      .ci-filter-type-select,
      .ci-filter-value-input {
        border: var(--wire-border);
        background: var(--surface-elevated);
        color: var(--text-primary);
      }
    }

    /* ── Ingest panel ───────────────────── */
    .ci-ingest-notes {
      label {
        color: var(--text-secondary);
      }

      textarea {
        border: var(--wire-border);
        background: var(--surface-elevated);
        color: var(--text-primary);
      }
    }

    .ci-ingest-intro {
      border: var(--wire-border);
      background: var(--surface-elevated);

      p {
        color: var(--text-secondary);
      }
    }

    /* ── Bulk dropzone ───────────────────── */
    .ci-bulk-dropzone {
      border: 2px dashed oklch(from var(--text-secondary) l c h / 0.3);
      background: oklch(from var(--glass-tint) l c h / 0.02);

      &[data-state='dragover'] {
        border-color: var(--accent-primary);
        background: oklch(from var(--accent-primary) l c h / 0.05);
      }

      .ci-bulk-dropzone-label {
        color: var(--text-secondary);

        .ci-bulk-dropzone-primary {
          color: var(--text-primary);
        }

        .ci-bulk-dropzone-secondary {
          color: var(--text-secondary);
        }
      }
    }

    .ci-bulk-list {
      .ci-bulk-item {
        border: var(--wire-border);
        background: var(--surface-elevated);

        .ci-bulk-item-name {
          color: var(--text-primary);
        }

        .ci-bulk-item-status {
          color: var(--text-secondary);
        }

        &[data-state='success'] .ci-bulk-item-status {
          color: var(--color-success);
        }

        &[data-state='error'] .ci-bulk-item-status {
          color: var(--color-error);
        }

        .ci-bulk-item-retry {
          border: var(--wire-border);
          background: transparent;
          color: var(--text-secondary);
        }
      }
    }

    .ci-bulk-summary {
      color: var(--text-secondary);
    }

    /* ── Intelligence tab — corpus analytics ───────────────────── */
    .ci-stats-total {
      border: var(--wire-border);
      background: var(--surface-elevated);

      .ci-stats-total-value {
        color: var(--accent-primary);
      }

      .ci-stats-total-label {
        color: var(--text-secondary);
      }
    }

    .ci-stats-card {
      background: var(--surface-elevated);
      border: var(--wire-border);

      h3 {
        color: var(--text-secondary);
      }

      .ci-stats-row {
        .ci-stats-row-label {
          color: var(--text-primary);
        }

        .ci-stats-row-bar {
          background: oklch(from var(--glass-tint) l c h / 0.06);

          .ci-stats-row-fill {
            background: linear-gradient(to right, var(--accent-primary), var(--accent-warm));
          }
        }

        .ci-stats-row-value {
          color: var(--text-secondary);
        }
      }
    }

    /* ── Integrations tab ───────────────────── */
    .ci-integrations-intro {
      border: var(--wire-border);
      background: var(--surface-elevated);

      p {
        color: var(--text-secondary);
      }
    }

    .ci-integration-card {
      background: var(--surface-elevated);
      border: var(--wire-border);

      p {
        color: var(--text-secondary);
      }
    }

    .ci-integration-status {
      background: oklch(from var(--glass-tint) l c h / 0.06);
      color: var(--text-secondary);
    }
  }

  /* Ingest result panel theme — see notes in components layer about
     why this isn't scoped under .candidate-intelligence-page. */
  .ci-ingest-result {
    border: var(--wire-border);
    background: var(--surface-elevated);

    p {
      color: var(--text-secondary);
    }
  }

  .ci-ingest-result--success {
    border-color: var(--color-success);
  }

  .ci-ingest-result--error {
    border-color: var(--color-error);

    h2 {
      color: var(--color-error);
    }
  }
}
