/* CRM library, file 6 of 7: the timeline. Loaded after lib/surface.css, before lib/data.css and app.css.

   Belongs here: ONE timeline, crm-journey, as components/journey.js builds it (journeyList), with the names of the older lead
   timeline (crm-inb-tl-*) as its aliases: the rail, the icon disc as the mark of its object, the month divider, head, when, text and
   meta, the dense variant for a side panel, and the states of the panel around it (journeyPanel: loading, empty, error, filters,
   more). The shapes and fills themselves are the block "Shapes and fills" of lib/chip.css, shared with the avatar.

   Contract: a base rule is ONE class, a modifier two, descendant parts go inside :where(); no id, no element selector, no @layer.
   The colour of an entry comes from the tone table in lib/chip.css through the --k-* knobs (data-kind on the item, or a tone word
   next to its class, or the hue of its object as data-hue on the disc), never from a class per kind: a new kind that is no object is
   one selector in that table plus one icon in JOURNEY_ICONS, a new object one line in the registry (components/shapes.js).
   Colour is never the only signal: every entry has an icon of its own and a title that says what happened.

   The knobs of the list (set them on crm-journey, the parts read them):
     --k-dot   the icon disc           --k-icon  the icon in it           --k-pad  the room above and under an entry
     --k-lead  what pushes the first line of the text to the middle of the disc      --k-max  where a line of text ends */

/* ── The list and its rail ─────────────────────────────────────────────────────────────────────────────────────────────────────
   The rail is drawn in pieces between the discs (above and under each one, with half the padding left open), so it needs no ring
   in the colour of what lies behind it: the timeline looks the same on a card, in a dialog and on the sunken row of a table. */
.crm-journey, .crm-inb-tl {
  --k-dot: 2rem; --k-icon: 1.0625rem; --k-pad: var(--sp-2); --k-lead: var(--sp-0); --k-max: 48rem;
  display: flex; flex-direction: column; max-width: var(--k-max); margin: 0; padding: 0; list-style: none;
}
/* dense: in a side panel (the quick view) */
.crm-journey.dense { --k-dot: 1.5rem; --k-icon: .875rem; --k-pad: var(--sp-1); --k-lead: 0rem; }
/* wide: the timeline is the whole card (a task, the Tijdlijn tab of a deal), the time at the right edge of the card */
.crm-journey.wide { --k-max: none; }
:where(.crm-journey, .crm-inb-tl) > :where(li) { position: relative; min-width: 0; }
:where(.crm-journey, .crm-inb-tl) > :where(li)::before,
:where(.crm-journey-item, .crm-inb-tl-item)::after { content: ''; position: absolute; left: calc(var(--k-dot) / 2 - .0625rem); width: .125rem; background: var(--line); }
/* above the disc of an entry, and under it down to the next one */
:where(.crm-journey-item, .crm-inb-tl-item)::before { top: 0; height: calc(var(--k-pad) / 2); }
:where(.crm-journey-item, .crm-inb-tl-item)::after { top: calc(var(--k-pad) * 1.5 + var(--k-dot)); bottom: 0; }
/* through a month divider */
:where(.crm-journey-month)::before { top: 0; bottom: 0; }
/* nothing above the first entry (also when a month stands above it) and nothing under the last */
:where(.crm-journey, .crm-inb-tl) > :where(li:first-child)::before,
:where(.crm-journey-month:first-child) + :where(li)::before,
:where(.crm-journey-item, .crm-inb-tl-item):where(:last-child)::after { display: none; }

/* ── An entry ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   The item carries the tone (data-kind, or ok | warn | bad | info | violet next to its class) and starts neutral, so a tone never
   leaks in from what the timeline stands in; the disc reads the knobs: the soft fill with the ink of the tone, as a chip does.
   The disc is the mark of the object the entry is about (components/shapes.js): its shape word next to its class (sq, squircle,
   octagon, rosette, ticket, drop, leaf: the knobs --k-r, --k-mask and --k-shrink of "Shapes and fills" in lib/chip.css) and its fill word
   (neutral, tint, solid) with the hue of the object as data-hue on the disc itself, so it wins from the colour of the kind on the
   item. Its line is an inset shadow and not a border, so the disc is its whole box in every shape and the rail meets the top and the
   bottom of a badge or an octagon as it meets a circle. */
:where(.crm-journey-item, .crm-inb-tl-item) {
  --k-ink: var(--muted); --k-bg: var(--surface); --k-accent: var(--faint); --k-solid: var(--crm-hue-slate-solid); --k-line: var(--line);
}
.crm-journey-item, .crm-inb-tl-item { display: grid; grid-template-columns: var(--k-dot) minmax(0, 1fr); gap: var(--sp-3); padding: var(--k-pad) 0; }
.crm-journey-icon, .crm-inb-tl-icon {
  --k-r: var(--pill); --k-mask: none; --k-shrink: 1; --k-ring: .0875rem;
  position: relative; display: grid; place-items: center; box-sizing: border-box; width: var(--k-dot); height: var(--k-dot);
  border-radius: var(--k-r); background: var(--k-bg); color: var(--k-ink); box-shadow: inset 0 0 0 1px var(--k-line);
  mask: var(--k-mask) center / 100% 100% no-repeat;
}
/* The line of a cut shape. A mask cuts the line of the box away with the corners, so the disc draws it again inside the shape: the
   shape minus the same shape a ring smaller, in --k-line (transparent for a toned disc and the same grey as a neutral fill, so only an
   entry without any colour shows it: white with a ring of --line, on a card and on the sunken row of a lead). --k-ring is about 1.4
   times the width of the line, because the outline of a badge or an octagon runs at a slant. On a circle or a square both images are
   none: a mask whose layers are all none is no mask and would show the whole box, so a third, transparent layer keeps it empty. */
:where(.crm-journey-icon, .crm-inb-tl-icon)::after {
  content: ''; position: absolute; inset: 0; background: var(--k-line); pointer-events: none;
  mask: var(--k-mask) center / 100% 100% no-repeat, var(--k-mask) center / calc(100% - var(--k-ring) * 2) calc(100% - var(--k-ring) * 2) no-repeat, linear-gradient(transparent, transparent);
  mask-composite: exclude;
}
/* the dense disc: a quarter of its width as the corner of a square, as the full size has */
:where(.crm-journey.dense) .crm-journey-icon.sq { --k-r: calc(var(--k-dot) / 4); }
/* `> .ms` and not `> :where(.ms)`: ds.css sizes every icon (`.ms { font-size: 1.2em }`), and a rule without weight loses from it */
:where(.crm-journey-icon, .crm-inb-tl-icon) > .ms { font-size: calc(var(--k-icon) * var(--k-shrink)); }
.crm-journey-body, .crm-inb-tl-body { min-width: 0; padding-top: var(--k-lead); }
.crm-journey-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.crm-journey-title, .crm-inb-tl-title { min-width: 0; font-weight: var(--crm-fw-semibold); overflow-wrap: anywhere; }
/* bridge: a title that is a link keeps the weight of a title (.crm .crm-link in app.css makes a link lighter) */
.crm a.crm-journey-title { font-weight: var(--crm-fw-semibold); }
/* the time: at the right of the title ("3 dagen geleden"), or the date itself as the first fact of the meta line */
.crm-journey-when { flex: none; color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
.crm-journey-text { margin-top: var(--sp-0); font-size: var(--fs-sm); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.crm-journey-meta { margin-top: var(--sp-0); color: var(--muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
/* a month: in line with the text of the entries, the rail runs past it */
.crm-journey-month { padding: var(--sp-2) 0 var(--sp-1) calc(var(--k-dot) + var(--sp-3)); color: var(--muted); font-size: var(--fs-xs); font-weight: var(--crm-fw-bold); letter-spacing: var(--crm-track-caps); text-transform: uppercase; }

/* ── The panel around it (journeyPanel) ────────────────────────────────────────────────────────────────────────────────────────
   Loading is three empty discs with grey lines in the measures of the timeline, so little jumps when the entries arrive; empty is one muted
   line; an error says what failed, with a button to try again; the filters are filter chips (lib/controls.css). */
.crm-journey-panel { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }
.crm-journey-skel { --k-dot: 2rem; --k-bg: var(--surface); --k-ink: var(--muted); --k-line: var(--line); display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-2) 0; }
.crm-journey-skel.dense { --k-dot: 1.5rem; gap: var(--sp-3); }
:where(.crm-journey-skel) > :where(div) { display: grid; grid-template-columns: var(--k-dot) minmax(0, 1fr); align-items: center; gap: var(--sp-3); }
:where(.crm-journey-skel) :where(.crm-skel) { margin: var(--sp-2) 0; }
.crm-journey-empty { margin: 0; color: var(--muted); font-size: var(--fs-sm); }
.crm-journey-error, .crm-timeline-error {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm); background: var(--coral-soft); color: var(--crm-bad-ink); font-size: var(--fs-sm);
}
:where(.crm-journey-error, .crm-timeline-error) > .ms { flex: none; font-size: var(--crm-icon-md); }
:where(.crm-journey-error, .crm-timeline-error) > :where(span:not(.ms)) { flex: 1 1 12rem; min-width: 0; overflow-wrap: anywhere; }
.crm-journey-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
/* what stands under the list (a button for older entries, a link to all of them) is as wide as its text */
:where(.crm-journey-panel) > :where(a, .btn) { align-self: flex-start; }

/* ── The activity list of a record (crm-act, pages/record/timeline.js) ─────────────────────────────────────────────────────────
   A work list of cards that fold open, not this timeline: it keeps its own build in app.css. Its icon is the icon of the kind
   in the ink of the kind, from the same registry and the same tone table (data-kind on the card), so a note is amber and a
   call green wherever they stand. */
:where(.crm-act) { --k-ink: var(--muted); }
.crm-act-icon { display: grid; place-items: start center; padding-top: var(--sp-3); color: var(--k-ink); }
