/* Heatmaps (crates/tally-web/src/heatmaps/): the page and viewport pickers, the map
   over the recorded page, and the counts beside it. Clicks warm from the visitors' blue
   (violet in the dark) to coral; rage is coral alone; dead clicks are grey rings; the
   scroll map shades the page by the share of pageviews still reading. */

.hm {
  --hm-c1: #3b78d8;
  --hm-c2: #6d5ce8;
  --hm-c3: #ec7d93;
  --hm-c4: #b4344f;
  --hm-rage-1: #f3b4c1;
  --hm-rage-2: #b4344f;
  --hm-dead: #6b7180;
  --hm-shade: 11, 13, 18;
}

:where(:root[data-theme="dark"]) .hm {
  --hm-c1: #7c3aed;
  --hm-c2: #b07cff;
  --hm-c3: #e0607a;
  --hm-c4: #f8b4c2;
  --hm-rage-1: #7a3446;
  --hm-rage-2: #f08aa0;
  --hm-dead: #a3a3a3;
  --hm-shade: 0, 0, 0;
}

@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) .hm {
    --hm-c1: #7c3aed;
    --hm-c2: #b07cff;
    --hm-c3: #e0607a;
    --hm-c4: #f8b4c2;
    --hm-rage-1: #7a3446;
    --hm-rage-2: #f08aa0;
    --hm-dead: #a3a3a3;
    --hm-shade: 0, 0, 0;
  }
}

.hm-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
}

.hm-bar .rp-menu {
  margin-left: 0;
}

.hm-bar .rp-menu .menu-value {
  max-width: 22em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

.hm-bar .rp-menu .menu-list {
  left: 0;
  right: auto;
  transform-origin: top left;
}

.hm-vps .tab,
.hm-kinds .tab {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  font-size: 13.5px;
}

.hm-vp[aria-disabled="true"] {
  color: var(--faint);
  opacity: .6;
  cursor: default;
}

.hm-kind {
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.hm-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.hm-board {
  padding: 14px;
  display: grid;
  gap: 12px;
  min-width: 0;
}

.hm-board-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hm-kinds {
  max-width: 100%;
  overflow-x: auto;
}

.hm-legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--faint);
  font-size: 12px;
}

.hm-legend-ramp {
  width: 96px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--hm-c1), var(--hm-c2), var(--hm-c3), var(--hm-c4));
  transition: background .3s ease;
}

.hm-board:has(.hm-stage[data-kind="rage"]) .hm-legend-ramp {
  background: linear-gradient(90deg, var(--hm-rage-1), var(--hm-rage-2));
}

.hm-board:has(.hm-stage[data-kind="dead"]) .hm-legend-ramp {
  background: linear-gradient(90deg, transparent, var(--hm-dead));
}

.hm-board:has(.hm-stage[data-kind="scroll"]) .hm-legend-ramp {
  background: linear-gradient(90deg, var(--faint), transparent);
}

/* The page, scaled to the board's width; the map over it. */
.hm-stage {
  position: relative;
  min-height: 320px;
  max-height: 1100px;
  overflow: hidden auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background:
    repeating-linear-gradient(45deg, transparent 0 10px, var(--line-2) 10px 11px),
    var(--paper);
  overscroll-behavior: contain;
}

.hm-frame {
  position: relative;
  transform-origin: 0 0;
}

.hm-frame .replayer-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: #ffffff;
}

.hm-frame iframe {
  display: block;
  border: 0;
  pointer-events: none;
  background: #ffffff;
}

.hm .replayer-mouse,
.hm .replayer-mouse-tail {
  display: none;
}

/* No recorded load: a blank page of the same width, so the points still have a shape. */
.hm-blank {
  position: absolute;
  top: 0;
  left: 0;
  background:
    linear-gradient(var(--line-2) 1px, transparent 1px) 0 0 / 100% 120px,
    #ffffff;
  box-shadow: 0 0 0 1px var(--line);
}

:where(:root[data-theme="dark"]) .hm-blank {
  background:
    linear-gradient(#202020 1px, transparent 1px) 0 0 / 100% 120px,
    #161616;
}

@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) .hm-blank {
    background:
      linear-gradient(#202020 1px, transparent 1px) 0 0 / 100% 120px,
      #161616;
  }
}

.hm-canvas,
.hm-scroll {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s var(--ease-out);
}

.hm-stage[data-state="ready"] .hm-canvas,
.hm-stage[data-state="ready"][data-kind="scroll"] .hm-scroll {
  opacity: 1;
}

.hm-scroll {
  right: 0;
}

.hm-reach {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1.5px dashed var(--ink);
}

.hm-reach-label {
  position: absolute;
  right: 8px;
  top: -13px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hm-reach-fold {
  border-top-style: solid;
  border-top-color: var(--visitors);
}

.hm-reach-fold .hm-reach-label {
  left: 8px;
  right: auto;
  background: var(--visitors);
  color: #ffffff;
}

/* An element named in "Most clicked", outlined on the page while it's hovered. */
.hm-focus {
  position: absolute;
  z-index: 3;
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(var(--hm-shade), .18);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease, left .25s var(--ease-out), top .25s var(--ease-out), width .25s var(--ease-out), height .25s var(--ease-out);
}

.hm-focus[data-on] {
  opacity: 1;
}

.hm-veil {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: opacity .35s ease, visibility .35s;
}

.hm-veil-loading {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  animation: rp-breathe 1.6s ease-in-out infinite;
}

.hm-stage:not([data-state="loading"]) .hm-veil {
  opacity: 0;
  visibility: hidden;
}

.hm-note,
.hm-small {
  color: var(--muted);
  font-size: 13px;
}

.hm-side {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.hm-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  overflow: hidden;
}

.hm-kpis > div {
  padding: 14px 16px;
}

.hm-kpis > div:nth-child(even) {
  border-left: 1px solid var(--line-2);
}

.hm-kpis > div:nth-child(n + 3) {
  border-top: 1px solid var(--line-2);
}

.hm-kpis dt {
  color: var(--muted);
  font-size: 13px;
}

.hm-kpis dd {
  margin: 2px 0 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hm-kpi-rage dd {
  color: var(--revenue-ink);
}

.hm-side-block {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.hm-sels,
.hm-qs {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 4px;
}

.hm-sel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas:
    "name n share"
    "bar  bar bar"
    "flags flags flags";
  align-items: baseline;
  gap: 3px 10px;
  padding: 7px 8px;
  border-radius: 6px;
  transition: background-color .15s ease;
  cursor: default;
}

.hm-sel:hover,
.hm-sel:focus-visible {
  background: var(--surface-2);
  outline-offset: -2px;
}

.hm-sel-name {
  grid-area: name;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  overflow-wrap: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
  font-size: 12px;
}

.hm-sel-n {
  grid-area: n;
  color: var(--ink);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.hm-sel-share {
  grid-area: share;
  min-width: 3.4em;
  color: var(--muted);
  font-size: 12.5px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hm-sel .hm-bar-svg {
  grid-area: bar;
}

.hm-sel-flags {
  grid-area: flags;
  display: flex;
  gap: 10px;
}

.hm-sel-flags:empty {
  display: none;
}

.hm-flag {
  font-size: 12px;
  font-weight: 600;
}

.hm-flag-rage {
  color: var(--revenue-ink);
}

.hm-flag-dead {
  color: var(--muted);
}

.hm-bar-svg {
  display: block;
  width: 100%;
  height: 4px;
  overflow: visible;
}

.hm-bar-track {
  fill: var(--line-2);
}

.hm-bar-fill {
  fill: var(--visitors);
  transform-box: fill-box;
  transform-origin: 0 50%;
  animation: hm-draw .9s var(--ease-out) both;
}

.hm-q {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 3.6em;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.hm-q-label {
  color: var(--muted);
}

.hm-q-n {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.hm-none {
  color: var(--muted);
  font-size: 13.5px;
}

.hm-empty {
  margin-top: 4px;
}

@keyframes hm-draw {
  from {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hm-bar-fill,
  .hm-veil-loading {
    animation: none;
  }

  .hm-canvas,
  .hm-scroll,
  .hm-focus {
    transition: none;
  }
}

@media (max-width: 1080px) {
  .hm-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .hm-side {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .hm-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hm-kpis > div:nth-child(n + 3) {
    border-top: 0;
  }

  .hm-kpis > div + div {
    border-left: 1px solid var(--line-2);
  }
}

@media (max-width: 560px) {
  .hm-bar .rp-menu {
    flex: 1 1 100%;
  }

  .hm-bar .rp-menu .menu-button {
    width: 100%;
    justify-content: space-between;
  }

  .hm-bar .rp-menu .menu-value {
    max-width: 11em;
  }

  .hm-board {
    padding: 10px;
  }

  .hm-kinds {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .hm-kinds .tab {
    justify-content: space-between;
    white-space: nowrap;
  }

  .hm-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hm-kpis > div:nth-child(n + 3) {
    border-top: 1px solid var(--line-2);
  }

  .hm-kpis > div:nth-child(3) {
    border-left: 0;
  }

  .hm-side {
    grid-template-columns: minmax(0, 1fr);
  }

  .hm-stage {
    max-height: 720px;
  }

  .hm-legend {
    display: none;
  }
}
