@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * CONNECTION INDICATOR
 *
 * Quiet inline status for a live connection: a dot (or an icon) and a word, with no pill around
 * them. The word is always muted; the glyph beside it carries the tone, taken from the semantic
 * status tokens (`--cinder-status-success-solid`, `--cinder-status-warning-text`,
 * `--cinder-border-contrast`) and never from hard-coded values. `live` is a green dot,
 * `out-of-date` a hollow ring in the pending colour, so neither reads as the other. `polling` is
 * deliberately quieter than `live`: it carries no motion and a lighter font-weight so it can never
 * be mistaken for push, even under grayscale or forced-colors rendering where the color
 * difference disappears.
 * ======================================== */

  .cinder-connection-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--cinder-space-1-5);
    color: var(--cinder-text-muted);
    font-size: var(--cinder-text-sm);
    font-weight: var(--cinder-font-medium);
    line-height: 1.25;
    white-space: nowrap;
    vertical-align: middle;
  }

  .cinder-connection-indicator__dot {
    display: inline-block;
    flex-shrink: 0;
    inline-size: 0.5rem;
    block-size: 0.5rem;
    border-radius: var(--cinder-radius-full);
    background: var(--_cinder-connection-indicator-dot-color, var(--cinder-status-success-solid));
  }

  /* The pending ring: the same hollow neutral ring a status dot draws for Waiting, so "Out of
     date" reads as unconfirmed rather than as a green or failed state. */
  .cinder-connection-indicator__ring {
    display: inline-block;
    flex-shrink: 0;
    box-sizing: border-box;
    inline-size: 0.5rem;
    block-size: 0.5rem;
    border: 0.09375rem solid var(--cinder-border-contrast); /* 1.5px */
    border-radius: var(--cinder-radius-full);
    background: transparent;
  }

  .cinder-connection-indicator[data-cinder-status='live'] .cinder-connection-indicator__dot {
    animation: cinder-connection-indicator-pulse var(--cinder-duration-pulse) ease-in-out infinite;
  }

  @media (prefers-reduced-motion: reduce) {
    :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
      .cinder-connection-indicator[data-cinder-status='live']
      .cinder-connection-indicator__dot {
      animation: none;
    }
  }

  @keyframes cinder-connection-indicator-pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.35;
    }
  }

  .cinder-connection-indicator__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    inline-size: 0.8125rem;
    block-size: 0.8125rem;
    color: currentColor;
  }

  /* The reconnecting dot is still and neutral: the same solid control-border dot a status dot draws
     for a neutral state. It is not green (not live) and does not pulse; the retry count belongs to
     the banner, so the indicator says only "Reconnecting". */
  .cinder-connection-indicator[data-cinder-status='reconnecting']
    .cinder-connection-indicator__dot {
    --_cinder-connection-indicator-dot-color: var(--cinder-border-contrast);
  }

  /* connecting spins the icon wrapper to signal in-progress work. This
 * targets the wrapper span (not the inner svg with a :global() selector) because this file is
 * a plain CSS asset imported from index.ts — the Svelte compiler never processes it, so
 * :global() has no effect here and browsers drop the whole rule as an unknown pseudo-class.
 * Rotating the wrapper rotates its svg child identically. */
  .cinder-connection-indicator[data-cinder-status='connecting'] .cinder-connection-indicator__icon {
    animation: cinder-connection-indicator-spin var(--cinder-duration-spin) linear infinite;
  }

  @media (prefers-reduced-motion: reduce) {
    :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
      .cinder-connection-indicator[data-cinder-status='connecting']
      .cinder-connection-indicator__icon {
      animation: none;
    }
  }

  @keyframes cinder-connection-indicator-spin {
    to {
      transform: rotate(360deg);
    }
  }

  .cinder-connection-indicator__label {
    color: inherit;
  }

  .cinder-connection-indicator__attempt {
    color: var(--cinder-text-muted);
    font-weight: var(--cinder-font-normal);
  }

  /* ----------------------------------------
 * Status → semantic token mapping
 *
 * The word stays muted in every state; the dot or icon carries the tone. `polling` reuses the
 * muted tone of `closed` but is disambiguated by its icon, its lack of motion (see above), and its
 * label text. Colour is never the sole signal (WCAG 1.4.1).
 * ---------------------------------------- */

  .cinder-connection-indicator[data-cinder-status='connecting'] .cinder-connection-indicator__icon {
    color: var(--cinder-status-warning-text);
  }

  .cinder-connection-indicator[data-cinder-status='polling'] {
    font-weight: var(--cinder-font-normal);
  }

  .cinder-connection-indicator[data-cinder-status='stale'] .cinder-connection-indicator__icon {
    color: var(--cinder-status-info-text);
  }
}
