/* CRM library, file 3 of 7: chips. Loaded after lib/base.css, before lib/controls.css and app.css.

   Belongs here: the tone table (which elements carry a tone, the hues by data-status and data-kind, the semantic tones ok, warn,
   bad, info and violet: custom properties only), the static chip on crm-badge with its aliases (tag, stage, task status, due date,
   subtasks and so on), crm-count, crm-dot, the avatar, and the shapes and fills of an object that the avatar and the disc of a
   timeline entry share. The interactive filter chip (crm-chip) is a control and lives in lib/controls.css.

   Contract: a base rule is ONE class, a modifier two, descendant parts go inside :where(); no id, no element selector, no @layer.
   A class moves in by joining its primitive's selector list as an alias (the first selector is the primitive) while its rule is cut
   from app.css in the same commit; colours come from tokens, a tone only sets --k-* knobs that every tone-aware element re-declares.

   The builders are in public/app/components/badge.js: badge(), pipelineTag(), stageTag(), count(), dot(), chipRow(). */

/* ── Tones ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   A tone is five knobs and nothing else:
     --k-ink     text on --k-bg and on a surface                  --k-bg     the soft fill
     --k-accent  the colour itself: a dot, an icon, a stripe      --k-solid  a fill under white text
     --k-line    the border of the soft fill
   Text on its fill is at least 4.5:1 (WCAG AA) in light and in dark, for every tone and every hue below. Light / dark, the dark
   soft colours of ds.css over --surface-2, where they are lowest:
     soft     neutral 5.5 / 6.5   ok 5.0 / 8.3   warn 4.6 / 8.5   bad 5.4 / 7.4   info 5.9 / 7.1   violet 7.8 / 7.2
              the hues (ink on the 14 % tint): slate 5.0 / 5.6, blue 5.5 / 7.8, amber 5.9 / 9.7, violet 7.3 / 7.7, green 6.4 / 9.1,
              pink 6.2 / 8.1, red 5.1 / 7.7, teal 6.0 / 9.8
     solid    white on slate 7.6 / 5.4, blue 5.2 / 4.7, amber 5.0 / 4.7, violet 5.7 / 5.6, green 4.7 / 4.7, pink 6.0 / 5.0, red 4.8 / 4.9, teal 5.4 / 5.0
     outline  ink on --surface: neutral 5.9 / 7.0, ok 5.5 / 11.7, warn 5.0 / 12.3, bad 6.3 / 9.4, info 6.7 / 9.9, violet 9.0 / 9.6
     plain    as outline; on --surface-2 the neutral one is 5.5 / 6.5

   1. Every element that reads the knobs starts neutral and declares all five on itself, so a tone never leaks in from an ancestor
      (custom properties inherit). A dot is the exception: it takes the tone of what it sits in. */
:where(.crm-badge, .crm-tag, .crm-stage, .crm-task-status, .crm-task-due, .crm-task-subs, .crm-kanban-date, .crm-assoc-tag, .crm-dupe-tag, .crm-wf-branch-pill, .crm-glyph) {
  --k-ink: var(--muted); --k-bg: var(--surface-2); --k-accent: var(--faint); --k-solid: var(--crm-hue-slate-solid); --k-line: var(--line);
}
/* 2. The hues, by what the element is about: the status of a task (data-status), the kind of a timeline entry (data-kind), or a colour
      of its own (data-hue: the colour of a record's avatar or of its pipeline, on the head of the quick view). A new status or kind is
      one selector in one of these lines. */
.crm :where([data-status="NOT_STARTED"], [data-kind="st_NOT_STARTED"], [data-kind="created"], [data-kind="edit"], [data-kind="archived"], [data-hue="slate"]) { --k-ink: var(--crm-hue-slate-ink); --k-accent: var(--crm-hue-slate); --k-solid: var(--crm-hue-slate-solid); --k-bg: color-mix(in srgb, var(--crm-hue-slate) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-status="IN_PROGRESS"], [data-kind="st_IN_PROGRESS"], [data-kind="email"], [data-kind="owner"], [data-hue="blue"]) { --k-ink: var(--crm-hue-blue-ink); --k-accent: var(--crm-hue-blue); --k-solid: var(--crm-hue-blue-solid); --k-bg: color-mix(in srgb, var(--crm-hue-blue) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-status="WAITING"], [data-kind="st_WAITING"], [data-kind="note"], [data-kind="due"], [data-hue="amber"]) { --k-ink: var(--crm-hue-amber-ink); --k-accent: var(--crm-hue-amber); --k-solid: var(--crm-hue-amber-solid); --k-bg: color-mix(in srgb, var(--crm-hue-amber) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-status="DEFERRED"], [data-kind="st_DEFERRED"], [data-kind="meeting"], [data-kind="subtask"], [data-hue="violet"]) { --k-ink: var(--crm-hue-violet-ink); --k-accent: var(--crm-hue-violet); --k-solid: var(--crm-hue-violet-solid); --k-bg: color-mix(in srgb, var(--crm-hue-violet) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-status="COMPLETED"], [data-kind="st_COMPLETED"], [data-kind="call"], [data-kind="subtask_done"], [data-hue="green"]) { --k-ink: var(--crm-hue-green-ink); --k-accent: var(--crm-hue-green); --k-solid: var(--crm-hue-green-solid); --k-bg: color-mix(in srgb, var(--crm-hue-green) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-kind="task"], [data-hue="pink"]) { --k-ink: var(--crm-hue-pink-ink); --k-accent: var(--crm-hue-pink); --k-solid: var(--crm-hue-pink-solid); --k-bg: color-mix(in srgb, var(--crm-hue-pink) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-kind="ticket"], [data-kind="priority"], [data-hue="red"]) { --k-ink: var(--crm-hue-red-ink); --k-accent: var(--crm-hue-red); --k-solid: var(--crm-hue-red-solid); --k-bg: color-mix(in srgb, var(--crm-hue-red) 14%, var(--surface)); --k-line: transparent; }
.crm :where([data-hue="teal"]) { --k-ink: var(--crm-hue-teal-ink); --k-accent: var(--crm-hue-teal); --k-solid: var(--crm-hue-teal-solid); --k-bg: color-mix(in srgb, var(--crm-hue-teal) 14%, var(--surface)); --k-line: transparent; }
/* 3. The semantic tones, after the hues so that a tone word wins from a data-kind on the same element. This is the one place where
      a bare tone word stands alone: it only sets knobs, so a match on an unrelated .ok (a toast, the sync pill) changes nothing.
      neutral = inactive or unknown, info = running or planned, warn = waiting or needs attention, ok = done or active,
      bad = failed, late or lost, violet = customised. */
.crm :where(.ok, .won) { --k-ink: var(--green-ink); --k-bg: var(--green-soft); --k-accent: var(--green); --k-solid: var(--crm-hue-green-solid); --k-line: transparent; }
.crm :where(.warn) { --k-ink: var(--amber-ink); --k-bg: var(--amber-soft); --k-accent: var(--amber); --k-solid: var(--crm-hue-amber-solid); --k-line: transparent; }
.crm :where(.bad, .lost, .late) { --k-ink: var(--crm-bad-ink); --k-bg: var(--coral-soft); --k-accent: var(--coral); --k-solid: var(--crm-hue-red-solid); --k-line: transparent; }
.crm :where(.info) { --k-ink: var(--crm-info-ink); --k-bg: var(--blue-soft); --k-accent: var(--blue); --k-solid: var(--crm-hue-blue-solid); --k-line: transparent; }
.crm :where(.violet) { --k-ink: var(--violet-ink); --k-bg: var(--violet-soft); --k-accent: var(--violet); --k-solid: var(--crm-hue-violet-solid); --k-line: transparent; }

/* ── A toned icon ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
   crm-glyph is a Material Symbol in the accent of a hue (data-hue) or a tone word: the status of a lead in its tab, the head of its column
   and the menu Naar status (18-11-2026, "statussen mogen unieke icoontjes met passende subtiele kleurtjes"). It always stands next to the
   text that says the same (colour never alone); the text keeps its own ink. The stylesheet writes the symbol from data-icon, so the text of
   the tab or the item stays its name (as crm-admin-mark does). toned: in the accent of its hue or tone; without it the colour of what it
   stands in (the icon of a chip). glyph() of components/badge.js builds it. */
.crm-glyph::before { content: attr(data-icon); }
.crm-glyph.toned { color: var(--k-accent); }

/* ── The static chip ───────────────────────────────────────────────────────────────────────────────────────────────────────────
   crm-badge says something (a status, a kind, a label); it is not a button. Four axes, each a word next to crm-badge:
     tone   neutral | ok | warn | bad | info | violet (or a hue through data-status / data-kind)
     shape  pill | sq            size  1.5rem | sm 1.25rem, both at --fs-xs            fill  soft | solid | outline | plain
   and two slots before the text: an icon (.ms) or a dot (.crm-dot). A chip always has text: nothing is said with colour alone.
   The aliases are the older names of the same chip; they keep their own shape through the modifier lists below. */
.crm-badge, .crm-tag, .crm-stage, .crm-task-status, .crm-task-due, .crm-task-subs, .crm-kanban-date, .crm-assoc-tag, .crm-dupe-tag, .crm-wf-branch-pill {
  display: inline-flex; align-items: center; gap: var(--sp-1); box-sizing: border-box; flex: none; vertical-align: middle;
  height: var(--crm-chip-h); max-width: 100%; padding: 0 var(--sp-3); overflow: hidden;
  border: 1px solid var(--k-line); border-radius: var(--pill); background: var(--k-bg); color: var(--k-ink);
  font-size: var(--fs-xs); font-weight: var(--crm-fw-semibold); line-height: 1.3; white-space: nowrap;
}
/* shape: a pipeline and a deal stage are square tags, a status is a pill */
.crm-badge.sq, .crm-tag, .crm-stage, .crm-assoc-tag { border-radius: var(--crm-radius-tag); }
/* size */
.crm-badge.sm, .crm-kanban-date { height: var(--crm-chip-h-sm); padding: 0 var(--sp-2); }
/* fill */
.crm-badge.solid, .crm-tag { border-color: transparent; background: var(--k-solid); color: var(--crm-on-solid); font-weight: var(--crm-fw-bold); }
.crm-badge.outline, .crm-dupe-tag, .crm-wf-branch-pill { border-color: var(--line-strong); background: var(--surface); }
.crm-badge.plain, .crm-task-due.none { padding: 0; border-color: transparent; background: none; font-weight: normal; }
/* what is not a tone word: an open deal stage is written in ink (won and lost take the tones ok and bad; all subtasks done is the
   tone ok and a late date .late, which the tone table knows), an exact duplicate (tone bad) has a border and a fill of its own, a free label and the name
   of a branch stop at 14rem, a pipeline takes one of six solids by its id (tagColor in components/badge.js; the order is fixed,
   or the pipelines change colour) */
.crm-stage:not(.won, .lost) { color: var(--ink); }
.crm-dupe-tag.exact { border-color: var(--k-accent); background: var(--k-bg); }
.crm-assoc-tag, .crm-wf-branch-pill { max-width: 14rem; }
.crm-tag.c1 { --k-solid: var(--crm-hue-green-solid); }
.crm-tag.c2 { --k-solid: var(--crm-hue-blue-solid); }
.crm-tag.c3 { --k-solid: var(--crm-hue-violet-solid); }
.crm-tag.c4 { --k-solid: var(--crm-hue-amber-solid); }
.crm-tag.c5 { --k-solid: var(--crm-hue-pink-solid); }
.crm-tag.c6 { --k-solid: var(--crm-hue-slate-solid); }
/* slots: one icon size, and text that shortens with an ellipsis when it is in a span of its own (the builders write it that way) */
:where(.crm-badge, .crm-tag, .crm-stage, .crm-task-status, .crm-task-due, .crm-task-subs, .crm-kanban-date, .crm-assoc-tag, .crm-dupe-tag, .crm-wf-branch-pill) > .ms { flex: none; margin-left: calc(var(--sp-0) * -1); font-size: var(--crm-icon-xs); }
:where(.crm-badge, .crm-tag, .crm-stage, .crm-task-status, .crm-task-due, .crm-task-subs, .crm-kanban-date, .crm-assoc-tag, .crm-dupe-tag, .crm-wf-branch-pill) > :where(span:not(.ms, .crm-dot)) { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ── Counts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   A number next to a title, a tab, a column or a filter: as high as a small chip, grey; solid for "this many filters are on";
   lg next to the title of a list. An empty count is not drawn, so it can stand in the page before the number is known.
   Text: muted on --line 4.8:1 light, 5.0:1 dark; white on the solid 5.2:1 light, 4.7:1 dark (on --blue it was 3.7:1 in dark). */
.crm-count, .crm-tab-count, .crm-kanban-count, .crm-chip-count {
  display: inline-grid; place-items: center; box-sizing: border-box; flex: none; min-width: var(--crm-chip-h-sm); height: var(--crm-chip-h-sm); padding: 0 var(--sp-2);
  border-radius: var(--pill); background: var(--line); color: var(--muted);
  font-size: var(--fs-xs); font-weight: var(--crm-fw-semibold); font-variant-numeric: tabular-nums; line-height: 1; white-space: nowrap;
}
:where(.crm-count, .crm-tab-count, .crm-kanban-count, .crm-chip-count):empty { display: none; }
.crm-count.solid, .crm-chip-count { background: var(--crm-hue-blue-solid); color: var(--crm-on-solid); font-weight: var(--crm-fw-bold); }
.crm-count.lg { min-width: 1.75rem; height: 1.75rem; padding: 0 var(--sp-4); font-size: var(--fs-md); }

/* ── Dots ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   The colour of a tone as a dot, always next to a text that says the same (aria-hidden; a dot alone says nothing). It does not
   reset the knobs: a dot takes the tone of what it sits in (a chip, the sync pill) unless it carries a tone word itself. */
.crm-dot { display: inline-block; flex: none; width: .5rem; height: .5rem; border-radius: var(--pill); background: var(--k-accent, var(--faint)); }
.crm-dot.pulse { animation: crm-dot-pulse 1.4s ease-in-out infinite; }
@keyframes crm-dot-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .crm-dot.pulse { animation: none; } }
/* on a solid chip the accent is the fill itself: the dot is drawn in the colour of the text */
:where(.crm-badge.solid, .crm-tag) > .crm-dot { background: currentColor; }

/* ── Avatars ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   The mark of a record, built by avatar() and recordAvatar() (components/avatar.js). Every type has the mark of its object (Marley
   12-11-2026 and 13-11-2026; the block Shapes and fills below): a person a squircle, a company a rounded square (sq), a deal a badge
   (rosette), a task an octagon. Sizes xs, sm, md, lg, xl; a record type without a name shows its icon in the fill of its object (icon plus neutral, tint
   or solid); initials take one of six colours (c1 to c6).
   The logo layer (logo-layer.js) lays a company's logo over its avatar (data-logo-company) on white, also in dark mode, so a dark logo
   stays visible. */
.crm-avatar {
  --k-size: 2.25rem; --k-icon: var(--crm-icon-md); --k-shrink: 1; --k-r: var(--pill); --k-mask: none;
  display: inline-grid; place-items: center; flex: none; width: var(--k-size); height: var(--k-size); border-radius: var(--k-r);
  mask: var(--k-mask) center / 100% 100% no-repeat; font-size: var(--fs-sm); font-weight: var(--crm-fw-bold); color: var(--crm-on-solid);
}
/* `> .ms` weighs a class next to the avatar, so it wins from ds.css `.ms { font-size: 1.2em }` */
.crm-avatar > .ms { font-size: calc(var(--k-icon) * var(--k-shrink)); }
.crm-avatar.xs { --k-size: 1.25rem; --k-icon: calc(var(--crm-icon-xs) * .8); font-size: calc(var(--fs-xs) * .75); }
.crm-avatar.sm { --k-size: var(--crm-av-sm); --k-icon: var(--crm-icon-xs); font-size: var(--fs-xs); }
.crm-avatar.lg { --k-size: 3rem; --k-icon: var(--crm-icon-lg); font-size: var(--fs-lg); }
.crm-avatar.xl { --k-size: 3.5rem; --k-icon: var(--crm-icon-lg); font-size: var(--fs-xl); } /* the head of the quick view (12-11-2026) */
.crm-avatar.c1 { background: var(--crm-av-1); }
.crm-avatar.c2 { background: var(--crm-av-2); }
.crm-avatar.c3 { background: var(--crm-av-3); }
.crm-avatar.c4 { background: var(--crm-av-4); }
.crm-avatar.c5 { background: var(--crm-av-5); }
.crm-avatar.c6 { background: var(--crm-av-6); }
.crm-avatar.photo { background: var(--line); overflow: hidden; } /* the profile photo of the hub (topbar.js) */
.crm-avatar.photo :where(img) { display: block; width: 100%; height: 100%; object-fit: cover; }
.crm-avatar[data-logo-company] { position: relative; }
.crm-avatar-logo { position: absolute; inset: 0; width: 100%; height: 100%; padding: 12%; border-radius: inherit; background: var(--crm-logo-bg); object-fit: contain; box-shadow: inset 0 0 0 1px var(--line); }
.crm-avatar-logo.on-dark { background: var(--crm-hue-slate-solid); } /* a light logo without a background of its own (logo-layer.js logoTone) */
/* an action in the top right corner of an avatar (avatar({ corner }): the logo sync of a company page, 16-11-2026); two classes, because
   the icon button of lib/controls.css loads after this file */
.crm-avatar-wrap { position: relative; display: inline-flex; flex: none; }
.crm-avatar-wrap > .crm-avatar-corner { position: absolute; top: -.375rem; right: -.375rem; border-radius: 50%; background: var(--surface); box-shadow: var(--crm-elev-raised); }

/* ── Shapes and fills ──────────────────────────────────────────────────────────────────────────────────────────────────────────
   The mark of an object, on its avatar and on the disc of a timeline entry about it (crm-journey-icon, lib/timeline.css). Which object
   has which shape, icon, fill and hue is ONE registry, components/shapes.js (OBJECTS: Marley's choice per object, 12-11-2026, one line
   each); its vocabulary of shapes (SHAPES) is the class word per shape: circle (no word: the base rule of each element), sq (square),
   squircle, octagon, rosette (the badge: badge is a word of ds.css), ticket, drop, leaf (13-11-2026). A shape only sets knobs, which
   both elements declare on
   their base rule and read in their own way:
     --k-r       the corner radius of a shape the box can draw (the circle is the pill of the base rule)
     --k-mask    the outline of a shape the box cannot draw: an SVG path with rounded corners that cuts the element out, so its fill, its
                 icon and its colours stay what they are (a disc with a line draws that line again inside the shape)
     --k-shrink  how much smaller the icon is where the shape leaves less room inside it
   A new shape is one rule here (a selector for each element that takes shapes) and one entry in SHAPES. */
.crm-avatar.sq, .crm-journey-icon.sq { --k-r: var(--r-sm); }
.crm-avatar.squircle, .crm-journey-icon.squircle { --k-r: 0; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50,4 C86,4 96,14 96,50 C96,86 86,96 50,96 C14,96 4,86 4,50 C4,14 14,4 50,4 Z' fill='black' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.crm-avatar.octagon, .crm-journey-icon.octagon { --k-r: 0; --k-shrink: .95; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpolygon points='67.2,8.4 91.6,32.8 91.6,67.2 67.2,91.6 32.8,91.6 8.4,67.2 8.4,32.8 32.8,8.4' fill='black' stroke='black' stroke-width='12' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.crm-avatar.rosette, .crm-journey-icon.rosette { --k-r: 0; --k-shrink: .9; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpolygon points='50.0,2.0 62.7,11.0 78.2,11.2 83.2,25.9 95.7,35.2 91.0,50.0 95.7,64.8 83.2,74.1 78.2,88.8 62.7,89.0 50.0,98.0 37.3,89.0 21.8,88.8 16.8,74.1 4.3,64.8 9.0,50.0 4.3,35.2 16.8,25.9 21.8,11.2 37.3,11.0' fill='black' stroke='black' stroke-width='6' stroke-linejoin='round'/%3E%3C/svg%3E"); }
/* a ticket: a notch in the middle of each side */
.crm-avatar.ticket, .crm-journey-icon.ticket { --k-r: 0; --k-shrink: .85; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M8,18 H92 V40 A10,10 0 0 0 92,60 V82 H8 V60 A10,10 0 0 0 8,40 Z' fill='black' stroke='black' stroke-width='8' stroke-linejoin='round'/%3E%3C/svg%3E"); }
/* a teardrop with its point at the top right */
.crm-avatar.drop, .crm-journey-icon.drop { --k-r: 0; --k-shrink: .9; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50,6 H94 V50 A44,44 0 1 1 50,6 Z' fill='black' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E"); }
/* a leaf: two corners round (top left, bottom right), two square */
.crm-avatar.leaf, .crm-journey-icon.leaf { --k-r: 0; --k-shrink: .9; --k-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M94,6 V50 A44,44 0 0 1 50,94 H6 V50 A44,44 0 0 1 50,6 Z' fill='black' stroke='black' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E"); }
/* a small mark keeps a quarter of its width as corner: the extra-small avatar here, the dense disc in lib/timeline.css */
.crm-avatar.sq:where(.xs) { --k-r: .3rem; }
/* The fill of a mark (FILLS of the registry), how it paints its hue:
     neutral  grey, the look an icon avatar always had: --muted on --line (4.8:1 light, 5.0:1 dark)
     tint     the soft tint of its hue in the ink of that hue: the knobs of the tone table, by data-hue on the mark (5.0:1 or more)
     solid    the solid of its hue under --crm-on-solid (4.7:1 or more)
   An avatar with initials has the solid colour of its id (c1 to c6) instead; an icon avatar is always icon plus its fill. */
.crm-avatar.icon, .crm-avatar.neutral, .crm-journey-icon.neutral { background: var(--line); color: var(--muted); }
.crm-avatar.tint, .crm-journey-icon.tint { background: var(--k-bg); color: var(--k-ink); }
.crm-avatar.solid, .crm-journey-icon.solid { background: var(--k-solid); color: var(--crm-on-solid); }
