/* ===========================================================================
   Shared components. Anything used by more than one app lives here; anything
   specific to a single view lives in that view's own stylesheet.
   Reference: docs/design/03-ui-patterns.md
   =========================================================================== */

@layer components {

  /* -------------------------------------------------------------------------
     Buttons
     ------------------------------------------------------------------------- */
  .bh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    /* No fixed widths anywhere: Spanish labels run 15-30% longer than English. */
    min-block-size: 44px;              /* tactile target floor */
    padding-inline: var(--sp-5);
    padding-block: var(--sp-2);
    border: 1px solid transparent;
    border-radius: var(--r-full);
    background: var(--bh-surface-2);
    color: var(--bh-chrome);
    font-size: var(--fs-body-s);
    font-weight: 600;
    text-decoration: none;
    transition:
      background var(--dur-instant) var(--ease-human),
      transform var(--dur-instant) var(--ease-human);
  }

  .bh-btn:hover { background: var(--bh-surface-3); }
  .bh-btn:active { transform: scale(0.98); }

  .bh-btn--primary {
    background: var(--bh-ember);
    /* Never white. White on Ember is 2.86:1 and fails WCAG. */
    color: var(--bh-on-accent);
  }
  .bh-btn--primary:hover {
    background: color-mix(in oklch, var(--bh-ember) 88%, white);
  }

  .bh-btn--quiet {
    background: transparent;
    border-color: var(--bh-hairline);
    color: var(--bh-titanium);
  }
  .bh-btn--quiet:hover { background: var(--bh-surface-1); color: var(--bh-chrome); }

  .bh-btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

  @supports (corner-shape: squircle) {
    .bh-btn:not(.bh-btn--pill) { corner-shape: squircle; }
  }

  /* -------------------------------------------------------------------------
     Card
     ------------------------------------------------------------------------- */
  .bh-card {
    padding: var(--sp-5);
    border: 1px solid var(--bh-hairline);
    /* Nested radius rule: inner radius = outer radius - padding. */
    border-radius: var(--r-lg);
    background: var(--bh-surface-1);
    box-shadow: var(--elev-1);
  }
  @supports (corner-shape: squircle) {
    .bh-card { corner-shape: squircle; }
  }

  .bh-card__title { margin-block-end: var(--sp-2); font-size: var(--fs-h3); }
  .bh-card__meta {
    color: var(--bh-titanium);
    font-size: var(--fs-caption);
  }

  /* -------------------------------------------------------------------------
     Trust badge

     Structural guarantee, not a convention: the label is a real element and
     the ring is aria-hidden, so the level cannot be rendered as colour alone.
     Level is read by arc length first, colour second, label third.
     ------------------------------------------------------------------------- */
  .bh-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding-inline: var(--sp-1) var(--sp-3);
    padding-block: var(--sp-1);
    border-radius: var(--r-full);
    background: var(--bh-surface-2);
    font-size: var(--fs-caption);
    font-weight: 500;
    white-space: nowrap;
  }

  /* The ring is drawn by .bh-arcmark in provenance.css, at its default 16px.
     No size override here on purpose: both selectors have the same specificity
     and live in the same layer, so whichever file loads last would silently win.
     One declaration, one place. */

  .bh-badge__label { color: var(--bh-chrome); }

  .bh-badge--none .bh-badge__label { color: var(--bh-titanium); }

  /* The Heartbeat. One pulse when a verified badge is revealed, never a loop.
     420ms, spring curve. It is the heartbeat, not a spinner. */
  .bh-badge--reveal { animation: bh-heartbeat var(--dur-slow) var(--ease-spring) both; }

  @keyframes bh-heartbeat {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.06); }
    100% { transform: scale(1); }
  }

  /* Entry animation for a badge that was already on the page at load. */
  @starting-style {
    .bh-badge { opacity: 0; }
  }

  /* -------------------------------------------------------------------------
     Provenance ring — the component version, for avatars and media thumbnails.
     Arc length is driven by --bh-arc so one rule covers every trust level.
     ------------------------------------------------------------------------- */
  .bh-ring {
    --bh-arc: 100%;
    --bh-ring-size: 44px;
    --bh-ring-w: 3px;

    position: relative;
    inline-size: var(--bh-ring-size);
    aspect-ratio: 1;
    border-radius: var(--r-full);
    background:
      conic-gradient(from -90deg,
        var(--bh-ring-color, var(--bh-aurora)) 0 var(--bh-arc),
        transparent var(--bh-arc) 100%),
      conic-gradient(var(--bh-surface-3) 0 100%);
    mask: radial-gradient(farthest-side,
      transparent calc(100% - var(--bh-ring-w)),
      black calc(100% - var(--bh-ring-w)));
  }

  .bh-ring--spectrum {
    background:
      conic-gradient(from -90deg in oklch,
        var(--bh-tone-1) 0,
        var(--bh-tone-4) calc(var(--bh-arc) / 2),
        var(--bh-tone-7) var(--bh-arc),
        transparent var(--bh-arc) 100%),
      conic-gradient(var(--bh-surface-3) 0 100%);
  }

  /* -------------------------------------------------------------------------
     Header and shell
     ------------------------------------------------------------------------- */
  .bh-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-block-size: 100dvh;
  }

  .bh-header {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    padding: var(--sp-3) var(--sp-5);
    border-block-end: 1px solid var(--bh-hairline);
    background: var(--bh-vapor);
    backdrop-filter: blur(16px) saturate(1.4);
  }

  .bh-header__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    color: var(--bh-chrome);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: -0.02em;
  }

  /* -------------------------------------------------------------------------
     The Arc, drawn in CSS instead of loaded as an SVG.

     The mark carries the Human Spectrum, and the spectrum uses a different ramp
     per theme, so any file with baked-in stops is wrong in one of them: the
     on-dark artwork's palest stop measures 1.09:1 against the light page. Drawn
     from tokens it follows the theme, and it costs no request.

     No track circle behind it, unlike the provenance ring: the logo IS the arc,
     and its incompleteness is the point. Verification is never finished.

     The SVG files stay in wwwroot/brand for email and Open Graph, where there is
     no CSS to read tokens from.
     ------------------------------------------------------------------------- */
  .bh-brandmark {
    --bh-brandmark-size: 28px;
    --bh-brandmark-w: 3px;
    --bh-arc: 78%;

    display: block;
    inline-size: var(--bh-brandmark-size);
    aspect-ratio: 1;
    flex: none;
    border-radius: var(--r-full);
    background: conic-gradient(from -90deg in oklch,
      var(--bh-tone-1) 0,
      var(--bh-tone-4) calc(var(--bh-arc) / 2),
      var(--bh-tone-7) var(--bh-arc),
      transparent var(--bh-arc) 100%);
    mask: radial-gradient(farthest-side,
      transparent calc(100% - var(--bh-brandmark-w)),
      black calc(100% - var(--bh-brandmark-w)));
  }

  .bh-header__nav {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    margin-inline-start: auto;
    font-size: var(--fs-body-s);
  }

  .bh-header__nav a {
    color: var(--bh-titanium);
    text-decoration: none;
  }
  .bh-header__nav a:hover,
  .bh-header__nav a[aria-current="page"] { color: var(--bh-chrome); }

  .bh-main {
    inline-size: 100%;
    max-inline-size: 1100px;
    margin-inline: auto;
    padding: var(--sp-7) var(--sp-5) var(--sp-9);
  }

  .bh-footer {
    padding: var(--sp-6) var(--sp-5);
    border-block-start: 1px solid var(--bh-hairline);
    color: var(--bh-titanium);
    font-size: var(--fs-caption);
  }

  /* -------------------------------------------------------------------------
     Language switcher. Always visible, never auto-magic: the culture is an
     explicit URL segment so links can be shared. See docs/rules/10-i18n.md.
     ------------------------------------------------------------------------- */
  .bh-lang {
    display: inline-flex;
    gap: var(--sp-05);
    padding: var(--sp-05);
    border: 1px solid var(--bh-hairline);
    border-radius: var(--r-full);
  }

  .bh-lang__opt {
    padding-inline: var(--sp-3);
    padding-block: var(--sp-1);
    border-radius: var(--r-full);
    color: var(--bh-titanium);
    font-size: var(--fs-caption);
    font-weight: 600;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .bh-lang__opt[aria-current="true"] {
    background: var(--bh-surface-3);
    color: var(--bh-chrome);
  }

  /* -------------------------------------------------------------------------
     Evidence block — hashes, credential IDs, Merkle paths.
     ------------------------------------------------------------------------- */
  .bh-evidence-row {
    display: grid;
    grid-template-columns: minmax(120px, auto) 1fr;
    gap: var(--sp-2) var(--sp-4);
    padding-block: var(--sp-2);
    border-block-end: 1px solid var(--bh-hairline);
    font-size: var(--fs-body-s);
  }

  .bh-evidence-row dt { color: var(--bh-titanium); }
  .bh-evidence-row dd {
    margin: 0;
    font-family: var(--ff-evidence);
    font-size: var(--fs-micro);
    overflow-wrap: anywhere;
  }

  /* Container queries, not viewport breakpoints: a component should respond to
     the space it is given, not to the size of the window. */
  .bh-grid {
    display: grid;
    gap: var(--sp-5);
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    container-type: inline-size;
  }
}
