/**
 * Fluid Framework - Badge Component
 * @layer components
 *
 * Small labels for status, categories, counts, and metadata.
 * Works standalone or positioned inside cards and other components.
 *
 * Usage:
 *   <span class="badge">Default</span>
 *   <span class="badge" data-variant="filled">Filled</span>
 *   <span class="badge" data-variant="outline">Outline</span>
 *   <span class="badge" data-status="good">Active</span>
 *   <span class="badge" data-status="warning">Pending</span>
 *   <span class="badge" data-status="error">Failed</span>
 *   <span class="badge" data-size="sm">Small</span>
 *   <span class="badge" data-size="lg">Large</span>
 *   <span class="badge" data-count>3</span>      a count: a circle for one digit
 *   <span class="pill">24 comments</span>         any small rounded label
 *   <span class="pill" data-count>12</span>       a count in a pill
 *
 * PILLS (2026-11-22, stack playbook design-and-ux.md "Pills"): one contract
 * for every small rounded label, so its text sits in the middle in any
 * font. Centred both ways, line-height 1, padding in em, tabular figures,
 * at least as wide as it is tall (one digit is a circle), and where the
 * browser has text-box, trimmed to the capitals so a face's ascent and
 * descent cannot push the text high or low. Knobs: --pill-pad-block
 * (0.35em), --pill-pad-inline (0.5em; a [data-count] takes the block padding, so one
 * digit is a circle),
 * --pill-radius (--radius-pill). Old-style figures (Georgia has no others)
 * hang below the line by design: a face with lining figures centres.
 * A site sets these, never its own line-height or nudges.
 */

@layer components {
  /* ========================================
     BASE BADGE
     ======================================== */

  /* The label voice in a 1px box: square (--radius-control), transparent. */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0.35em 0.6em;
    font: calc(600 + var(--_dark-weight)) var(--step--2) / 1.2 var(--font-body);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    border: var(--border-width) solid currentColor;
    border-radius: var(--radius-control);
    white-space: nowrap;
    vertical-align: middle;
    color: var(--color-text);
    background: transparent;
  }


  /* Optical centring (#179, PILLS below): the trimmed badge's padding adds
     back what the trim removes, so the height holds. */
  .badge { --_trim-pad: calc(0.35em + (1.2em - 1cap) / 2); }


  /* ========================================
     PILLS: the shared centring contract (see the header)
     ======================================== */

  :is(.pill, .badge[data-count]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    min-inline-size: calc(1em + 2 * var(--pill-pad-block, 0.35em) + 2 * var(--border-width));
    padding: var(--pill-pad-block, 0.35em) var(--pill-pad-inline, 0.5em);
    line-height: 1;
    letter-spacing: 0;
    font-variant-numeric: lining-nums;
    border-radius: var(--pill-radius, var(--radius-pill));
    white-space: nowrap;
    vertical-align: middle;
  }
  .pill {
    font-size: var(--step--1);
    font-weight: calc(600 + var(--_dark-weight));
    color: var(--color-text);
    background: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
  }
  /* A count is a number, not a label: no capitals, and side padding no wider
     than the top and bottom, so one digit in any face is a circle. */
  /* Tabular figures for counts only: a count that ticks keeps its width, but in a
     label they widen the punctuation (Schibsted Grotesk's comma, Holiyay 2026-11-23). */
  :is(.pill, .badge)[data-count] { --pill-pad-inline: var(--pill-pad-block, 0.35em); text-transform: none; font-variant-numeric: lining-nums tabular-nums; }

  :is(.pill, .badge[data-count]) { --_trim-pad: calc(var(--pill-pad-block, 0.35em) + (1em - 1cap) / 2); }

  /* The one trim for every text-only pill (badge, count, .pill, chip, avatar,
     step marker): set on its capitals, centred, its padding (--_trim-pad, set
     by each component) adding back what the trim removes. The :not([hidden])
     outranks the components linked after this file (chip, steps) that set a
     flex display. */
  @supports (text-box: trim-both cap alphabetic) {
    :is(.badge, .pill, .chip, .avatar, .steps__marker):not(:has(> *)):not([hidden]) {
      display: inline-block;
      text-align: center;
      text-box: trim-both cap alphabetic;
      padding-block: var(--_trim-pad);
    }
  }


  /* ========================================
     VARIANTS
     ======================================== */

  /* Filled - solid accent background */
  .badge[data-variant="filled"] {
    color: var(--on-accent);
    background: var(--accent);
    border-color: transparent;
  }

  /* Outline - border only */
  .badge[data-variant="outline"] {
    background: transparent;
    border: var(--border-width) solid currentColor;
  }

  /* Muted - subtle neutral tones */
  .badge[data-variant="muted"] {
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-color: transparent;
  }


  /* ========================================
     STATUS COLORS
     Semantic states for indicators
     ======================================== */

  /* The status colours are text colours (4.5:1 on their own tint in light
     and dark); filled badges use the status fill and its on-colour. */
  .badge[data-status="good"] {
    color: var(--color-success);
    background: var(--color-success-subtle);
  }

  .badge[data-status="warning"] {
    color: var(--color-warning);
    background: var(--color-warning-subtle);
  }

  .badge[data-status="error"] {
    color: var(--color-error);
    background: var(--color-error-subtle);
  }

  .badge[data-status="info"] {
    color: var(--color-info);
    background: var(--color-info-subtle);
  }

  .badge[data-status="good"][data-variant="filled"] {
    color: var(--color-success-on);
    background: var(--color-success-fill);
  }

  .badge[data-status="warning"][data-variant="filled"] {
    color: var(--color-warning-on);
    background: var(--color-warning-fill);
  }

  .badge[data-status="error"][data-variant="filled"] {
    color: var(--color-error-on);
    background: var(--color-error-fill);
  }

  .badge[data-status="info"][data-variant="filled"] {
    color: var(--color-info-on);
    background: var(--color-info-fill);
  }


  /* ========================================
     SIZES
     ======================================== */

  .badge[data-size="sm"] {
    padding: 0.2em 0.45em;
    font-size: 0.6875rem;
  }

  .badge[data-size="lg"] {
    padding: 0.5em 0.8em;
    font-size: var(--step--1);
  }


  /* ========================================
     BADGE WITH DOT
     Status dot indicator before text
     ======================================== */

  .badge[data-dot]::before {
    content: "";
    inline-size: 0.375rem;
    block-size: 0.375rem;
    border-radius: var(--radius-full);
    background: currentColor;
    flex-shrink: 0;
  }


  /* ========================================
     BADGE COUNT
     Numeric counters (notifications, etc.)
     ======================================== */

  /* .badge[data-count] is a pill: see PILLS above. */



}
