/* ==========================================================================
   Chips — small values you can remove, toggle or type (see tag-input.css)

   <span class="chip">Design</span>
   <span class="chip chip-green"><i class="mi mi-check"></i>Paid</span>
   <span class="chip"><span class="chip-label">Ana Kim</span><button class="chip-remove" aria-label="Remove Ana Kim"></button></span>
   <span class="chip"><span class="chip-key">Status</span>Paid<button class="chip-remove" aria-label="Remove filter"></button></span>

   .chip-group            a wrapping row of chips          .chip-group-scroll   one row that scrolls (phones)
   .chip-clear            "Clear all" — with data-moey-chips-clear it removes every chip in the group
                          and hides itself once the group is empty
   Toggle chips (filters), two ways:
     <label class="chip"><input type="checkbox" name="status" value="paid">Paid</label>   ← in a form, no JS
     <div class="chip-group" data-moey-chips="multiple|single">
       <button class="chip" aria-pressed="false">Paid</button>                           ← moey.js flips it
   Off, a toggle chip is neutral; on, it's solid in its color (.chip-green …).
   .chip-pill · .chip-sm · .chip-lg · strengths .chip-subtle … .chip-deep
   ========================================================================== */

.chip {
  --_chip-fg: var(--mo-fg-body);
  --_chip-bg: color-mix(in oklab, var(--mo-fg-body) 8%, transparent);
  --_chip-h: 1.625rem;
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: .3125rem;
  max-width: 100%;
  height: var(--_chip-h);
  padding-inline: .5625rem;
  font-size: .8125rem;
  font-weight: var(--mo-font-weight-medium);
  line-height: 1;
  color: var(--_chip-fg);
  white-space: nowrap;
  vertical-align: middle;
  background: var(--_chip-bg);
  border-radius: calc(var(--mo-radius-control) - 2px);
}
/* Colors & strengths, like buttons: .chip-green (soft default fill) · .chip-subtle … .chip-deep */
:is(/*@colors chip*/), .chip:where(/*@themes*/) { --_chip-fg: var(--mo-theme-fill-text); --_chip-bg: var(--mo-theme-fill); }
.chip-subtle { --_chip-fg: var(--mo-theme-subtle-text); --_chip-bg: var(--mo-theme-subtle); }
.chip-soft   { --_chip-fg: var(--mo-theme-soft-text);   --_chip-bg: var(--mo-theme-soft); }
.chip-solid  { --_chip-fg: var(--mo-theme-solid-text);  --_chip-bg: var(--mo-theme-solid); }
.chip-vivid  { --_chip-fg: var(--mo-theme-vivid-text);  --_chip-bg: var(--mo-theme-vivid); }
.chip-deep   { --_chip-fg: var(--mo-theme-deep-text);   --_chip-bg: var(--mo-theme-deep); }
.chip-pill { border-radius: var(--mo-radius-pill); }
.chip-sm { --_chip-h: 1.375rem; gap: .25rem; padding-inline: .4375rem; font-size: .75rem; }
.chip-lg { --_chip-h: 2rem; gap: .375rem; padding-inline: .75rem; font-size: .875rem; }

.chip > .mi { font-size: 1.15em; }
.chip > .avatar { --mo-avatar-size: calc(var(--_chip-h) - .5rem); margin-inline-start: -.3125rem; font-size: .5625rem; }
.chip-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chip-key { font-weight: var(--mo-font-weight-normal); opacity: .8; }   /* Status  Paid — the name of an active filter */

/* The × — drawn inside the button, so the button can reach further than it looks */
.chip-remove {
  position: relative;
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  padding: 0;
  margin-inline: -.125rem -.3125rem;
  color: inherit;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: 50%;
  opacity: .6;
}
.chip-remove::before {
  position: absolute;
  inset: 0;
  content: "";
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 4.5l7 7m0-7l-7 7' stroke='black' stroke-width='1.75' stroke-linecap='round'/%3E%3C/svg%3E") center / .75rem no-repeat;
}
.chip-remove:is(:hover, :focus-visible) { background-color: color-mix(in oklab, currentColor 14%, transparent); opacity: 1; }
.chip-remove:focus-visible { outline: 0; }
.chip:has(> .chip-remove:focus-visible) { box-shadow: 0 0 0 var(--mo-focus-ring-width) var(--mo-theme-focus-ring); }
.chip-lg > .chip-remove { width: 1.25rem; height: 1.25rem; }
/* Fingers: a 36px-tall target around a 16px × */
@media (pointer: coarse) {
  .chip-remove::after { position: absolute; inset: -.625rem -.5rem; content: ""; }
}

/* Toggle chips ---------------------------------------------------------------------- */
button.chip { cursor: pointer; border: 0; font-family: inherit; }
label.chip { position: relative; margin: 0; cursor: pointer; user-select: none; }
label.chip > input:is([type="checkbox"], [type="radio"]) {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
  opacity: 0;
}
:is(button.chip, label.chip, a.chip):hover { background-image: linear-gradient(color-mix(in oklab, currentColor 10%, transparent) 0 0); }
a.chip { text-decoration: none; }
/* Off: neutral, whatever its color · On: solid in its color */
:is([data-moey-chips] button.chip:not([aria-pressed="true"]), button.chip[aria-pressed="false"], label.chip:not(:has(> input:checked))) {
  --_chip-fg: var(--mo-fg-body);
  --_chip-bg: color-mix(in oklab, var(--mo-fg-body) 8%, transparent);
}
:is(button.chip[aria-pressed="true"], label.chip:has(> input:checked)) {
  --_chip-fg: var(--mo-theme-solid-text);
  --_chip-bg: var(--mo-theme-solid);
}
:is(button.chip, a.chip):focus-visible { outline: 0; box-shadow: 0 0 0 var(--mo-focus-ring-width) var(--mo-theme-focus-ring); }
label.chip:has(> input:focus-visible) { box-shadow: 0 0 0 var(--mo-focus-ring-width) var(--mo-theme-focus-ring); }
:is(button.chip:disabled, label.chip:has(> input:disabled)) { cursor: not-allowed; background-image: none; opacity: .5; }

/* Groups ----------------------------------------------------------------------------- */
.chip-group { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-width: 0; }
.chip-group:focus { outline: 0; }
/* One row that scrolls sideways — filter bars on phones. Room is kept for focus rings. */
.chip-group-scroll {
  flex-wrap: nowrap;
  padding: 3px;
  margin: -3px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.chip-group-scroll::-webkit-scrollbar { display: none; }

.chip-clear {
  flex-shrink: 0;
  height: 1.625rem;
  padding: 0 .375rem;
  font: inherit;
  font-size: .8125rem;
  font-weight: var(--mo-font-weight-medium);
  color: var(--mo-fg-2);
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: 0;
  border-radius: calc(var(--mo-radius-control) - 2px);
}
.chip-clear:hover { color: var(--mo-fg-body); text-decoration: underline; text-underline-offset: .2em; }
.chip-clear:focus-visible { outline: 0; box-shadow: 0 0 0 var(--mo-focus-ring-width) var(--mo-default-focus-ring); }
.chip-group:not(:has(.chip)) > .chip-clear { display: none; }
