/*
 * Responsible for: how the colour breakdown under the Map looks: the thin stacked bar, the chips,
 * the light-up of a chip and its piece of the bar, and the reserved line for the description.
 *
 * Must never: change height when a description appears (its line is always reserved), animate
 * anything but transform and opacity, or hold a raw colour. Values come from tokens.css only.
 */

@layer kit {
  .ia-breakdown {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    min-width: 0;
    max-width: 100%;
  }

  .ia-breakdown__bar {
    display: flex;
    gap: 2px;
    height: var(--s-2);
    overflow: hidden;
    border-radius: var(--r-pill);
  }

  /* The inline style gives each piece its width as a share of the emails (flex-grow). */
  .ia-breakdown__piece {
    min-width: 3px;
    background: var(--c);
    cursor: pointer;
    transition: opacity var(--fast) var(--ease);
  }

  .ia-breakdown.has-active .ia-breakdown__piece:not(.is-lit) {
    opacity: 0.35;
  }

  /* With no pieces the bar is a plain track, not a missing line. */
  .ia-breakdown__bar:empty {
    background: var(--rule);
  }

  .ia-breakdown__chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-1) var(--s-2);
    min-width: 0;
    min-height: calc(var(--s-5) + var(--s-1));
    /* Three rows at most: a folder with many senders scrolls its chips inside, so it never squeezes the Map. */
    max-height: calc(3 * (var(--s-5) + var(--s-1)) + 2 * var(--s-1) + 6px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    /* Room so the keyboard's outline on an edge chip is not cut off by the scroll box. */
    padding: 3px;
    margin: -3px;
  }

  .ia-breakdown__none {
    margin: 0;
    color: var(--muted);
    font-size: var(--t-sm);
  }

  .ia-breakdown__chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    max-width: 100%;
    height: calc(var(--s-5) + var(--s-1));
    margin: 0;
    padding: 0 var(--s-3);
    border: 0;
    border-radius: var(--r-pill);
    background: var(--panel);
    box-shadow: inset 0 0 0 1px var(--rule);
    color: var(--ink);
    font: inherit;
    font-size: var(--t-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .ia-breakdown__chip::before,
  .ia-breakdown__chip::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--fast) var(--ease);
  }

  .ia-breakdown__chip::before {
    background: var(--c);
    opacity: 0;
  }

  .ia-breakdown__chip::after {
    box-shadow: inset 0 0 0 2px var(--c);
  }

  .ia-breakdown__chip.is-lit::before {
    opacity: 0.14;
  }

  .ia-breakdown__chip.is-lit::after {
    opacity: 1;
  }

  .ia-breakdown__chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .ia-breakdown__dot {
    flex: 0 0 auto;
    width: var(--s-2);
    height: var(--s-2);
    border-radius: var(--r-pill);
    background: var(--c);
  }

  .ia-breakdown__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
  }

  .ia-breakdown__pct {
    flex: 0 0 auto;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

  /* One line (two on a phone) is always reserved, so showing a description moves nothing. */
  .ia-breakdown__desc {
    height: calc(var(--t-sm) * 1.4);
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: var(--t-sm);
    line-height: 1.4;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  @media (max-width: 600px) {
    .ia-breakdown__chips {
      flex-wrap: nowrap;
      overflow-x: auto;
      overscroll-behavior-x: contain;
      overflow-y: hidden;
      scrollbar-width: none;
    }

    .ia-breakdown__chips::-webkit-scrollbar {
      display: none;
    }

    .ia-breakdown__chip {
      flex: 0 0 auto;
      height: var(--tap);
    }

    .ia-breakdown__desc {
      height: calc(var(--t-sm) * 2.8);
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      white-space: normal;
    }
  }
}
