html:root {
  --evolvium-cursor-arrow: url("/assets/img/cursors/arrow.svg") 0 0, none;
  --evolvium-cursor-click: url("/assets/img/cursors/pointer-click.svg") 11 0, none;
  --evolvium-cursor-hand: url("/assets/img/cursors/hand-grab.svg") 14 15, none;
  --evolvium-cursor-resize-x: url("/assets/img/cursors/resize-horizontal.svg") 15 12, none;
  --evolvium-cursor-resize-y: url("/assets/img/cursors/resize-vertical.svg") 12 15, none;
  --evolvium-cursor-current: var(--evolvium-cursor-arrow);
}

/*
 * EVOLVIUM owns the cursor over the complete rendered document. The terminal
 * `none` fallback is intentional: if an SVG cannot be loaded, a browser cursor
 * must not silently reappear.
 */
html:root,
html:root *,
html:root *::before,
html:root *::after {
  cursor: var(
    --evolvium-cursor-force,
    var(--evolvium-cursor-current, var(--evolvium-cursor-arrow))
  ) !important;
}

/* Activation controls. Descendants inherit the same cursor, including SVGs. */
html:root body :where(
  a[href],
  area[href],
  button:not(:disabled):not([aria-disabled="true"]),
  input:not(:disabled):not([aria-disabled="true"]),
  select:not(:disabled):not([aria-disabled="true"]),
  textarea:not(:disabled):not([aria-disabled="true"]),
  summary,
  label[for],
  label:has(input:not(:disabled), select:not(:disabled), textarea:not(:disabled)),
  [contenteditable]:not([contenteditable="false"]),
  [onclick],
  [role="button"]:not([aria-disabled="true"]),
  [role="checkbox"]:not([aria-disabled="true"]),
  [role="combobox"]:not([aria-disabled="true"]),
  [role="link"]:not([aria-disabled="true"]),
  [role="menuitem"]:not([aria-disabled="true"]),
  [role="menuitemcheckbox"]:not([aria-disabled="true"]),
  [role="menuitemradio"]:not([aria-disabled="true"]),
  [role="option"]:not([aria-disabled="true"]),
  [role="radio"]:not([aria-disabled="true"]),
  [role="slider"]:not([aria-disabled="true"]),
  [role="spinbutton"]:not([aria-disabled="true"]),
  [role="switch"]:not([aria-disabled="true"]),
  [role="tab"]:not([aria-disabled="true"]),
  [role="treeitem"]:not([aria-disabled="true"]),
  .my-colorpicker__free-plane,
  .my-colorpicker__grayscale-band,
  .my-colorpicker__transparency-band
) {
  --evolvium-cursor-current: var(--evolvium-cursor-click) !important;
}

/* Explicit extension point for application and shared-component markup. */
html:root body :where([data-evolvium-cursor="arrow"]) {
  --evolvium-cursor-current: var(--evolvium-cursor-arrow) !important;
}

html:root body :where([data-evolvium-cursor="click"]) {
  --evolvium-cursor-current: var(--evolvium-cursor-click) !important;
}

html:root body :where([data-evolvium-cursor="hand"]) {
  --evolvium-cursor-current: var(--evolvium-cursor-hand) !important;
}

html:root body :where([data-evolvium-cursor="resize-x"]) {
  --evolvium-cursor-current: var(--evolvium-cursor-resize-x) !important;
}

html:root body :where([data-evolvium-cursor="resize-y"]) {
  --evolvium-cursor-current: var(--evolvium-cursor-resize-y) !important;
}

/* The timeline arrow and its time chip are a single native cursor image. */
html:root body #planner-timeline {
  --evolvium-cursor-current: var(
    --evolvium-planner-time-cursor,
    var(--evolvium-cursor-arrow)
  ) !important;
}

/* Appointment drag handles remain neutral until an actual drag starts. */
html:root body :where(.planner-card__drag-handle) {
  --evolvium-cursor-current: var(
    --evolvium-planner-time-cursor,
    var(--evolvium-cursor-arrow)
  ) !important;
}

/* Draggable shared components expose the custom hand at their drag surface. */
html:root body :where(
  [draggable="true"],
  .my-colorpicker--draggable,
  .my-popup--draggable,
  .my-table__reorder-handle
) {
  --evolvium-cursor-current: var(--evolvium-cursor-hand) !important;
}

html:root body :where([data-my-colorpicker-no-drag]) {
  --evolvium-cursor-current: var(--evolvium-cursor-arrow) !important;
}

html:root body :where(
  .my-colorpicker__free-plane,
  .my-colorpicker__grayscale-band,
  .my-colorpicker__transparency-band
) {
  --evolvium-cursor-current: var(--evolvium-cursor-click) !important;
}

/* Resize affordances at rest. */
html:root body :where(.my-table__resize-handle) {
  --evolvium-cursor-current: var(--evolvium-cursor-resize-x) !important;
}

html:root body :where(.planner-card--timeline)::before,
html:root body :where(.planner-card--timeline)::after {
  --evolvium-cursor-current: var(--evolvium-cursor-resize-y) !important;
}

/* Disabled state outranks every at-rest affordance, but not an active gesture. */
html:root body :where(
  :disabled,
  :disabled *,
  [aria-disabled="true"],
  [aria-disabled="true"] *,
  [aria-busy="true"],
  [aria-busy="true"] *,
  [inert],
  [inert] *
) {
  --evolvium-cursor-current: var(--evolvium-cursor-arrow) !important;
}

/* Active gesture state is inherited from html and cannot change across targets. */
html:root:where(:has(
  [draggable="true"]:active,
  body.planner-document--dragging,
  .my-colorpicker--dragging,
  .my-gallery-carousel--dragging,
  .my-gallery-lightbox__track--dragging,
  .my-popup--dragging,
  .planner-card__drag-handle:active,
  .planner-card--dragging,
  .planner-flow--panning,
  .planner-page--dragging,
  .planner-ribbon--panning,
  .planner-ribbon-hot-zone--active
)) {
  --evolvium-cursor-force: var(--evolvium-cursor-hand) !important;
}

html:root:where(:has(.my-table--resizing)) {
  --evolvium-cursor-force: var(--evolvium-cursor-resize-x) !important;
}

/* Vertical appointment resize has the final priority over every other state. */
html:root:where(:has(
  body.planner-document--resizing,
  .planner-card--resizing,
  .planner-page--resizing
)) {
  --evolvium-cursor-force: var(--evolvium-cursor-resize-y) !important;
}
