/* Tally's live page (/sites/{id}/live): the globe or the map, the list beside it, the
   replay under it. Tokens are tokens.css; the globe reads its colours from the --lv-globe-*
   properties below, so both schemes come from here. Motion is transform and opacity only;
   every box holds its size (the stage and the list are fixed-height, the list scrolls),
   so an update never moves the page. Nothing moves for prefers-reduced-motion. */

.lv {
  --lv-stage-height: 540px;
  --lv-map-aspect: 2.336;
  --lv-globe-body-0: #ffffff;
  --lv-globe-body-1: #fbfcfe;
  --lv-globe-body-2: #eef1f7;
  --lv-globe-rim: #e0e6ef;
  --lv-globe-halo-inner: rgba(227, 236, 248, .9);
  --lv-globe-halo-middle: rgba(237, 242, 250, .45);
  --lv-globe-grid: rgba(214, 222, 234, .7);
  --lv-globe-land: #d4dce8;
  --lv-map-land: #d6dde8;
  --lv-pin: var(--visitors);
  --lv-pin-halo: rgba(59, 120, 216, .16);
  --lv-pin-edge: var(--surface);
  --lv-sale: var(--revenue);
  --lv-sale-halo: rgba(236, 125, 147, .2);
  --lv-focus: var(--brand);
  --lv-bar: #d5e2f5;
  --lv-bar-current: var(--visitors);
}

:where(:root[data-theme="dark"]) .lv {
  --lv-globe-body-0: #1c1c1e;
  --lv-globe-body-1: #161617;
  --lv-globe-body-2: #111112;
  --lv-globe-rim: #2c2c2e;
  --lv-globe-halo-inner: rgba(124, 58, 237, .2);
  --lv-globe-halo-middle: rgba(124, 58, 237, .07);
  --lv-globe-grid: rgba(255, 255, 255, .055);
  --lv-globe-land: #3b3b3f;
  --lv-map-land: #37373b;
  --lv-bar: #33275a;
  --lv-pin-halo: rgba(157, 107, 255, .2);
  --lv-sale-halo: rgba(224, 96, 122, .24);
  --lv-focus: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) .lv {
    --lv-globe-body-0: #1c1c1e;
    --lv-globe-body-1: #161617;
    --lv-globe-body-2: #111112;
    --lv-globe-rim: #2c2c2e;
    --lv-globe-halo-inner: rgba(124, 58, 237, .2);
    --lv-globe-halo-middle: rgba(124, 58, 237, .07);
    --lv-globe-grid: rgba(255, 255, 255, .055);
    --lv-globe-land: #3b3b3f;
    --lv-map-land: #37373b;
    --lv-bar: #33275a;
    --lv-pin-halo: rgba(157, 107, 255, .2);
    --lv-sale-halo: rgba(224, 96, 122, .24);
    --lv-focus: var(--ink);
  }
}

/* Head: the view switch sits where the dashboard's period menu does. */

.lv-head {
  margin-bottom: 18px;
}

.lv-switch {
  display: inline-flex;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-2);
}

.lv-switch-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 540;
  text-decoration: none;
  transition: background-color .2s ease, color .2s ease;
}

.lv-switch-option:hover {
  color: var(--ink);
}

.lv-switch-option[aria-current="true"] {
  background: var(--button-bg);
  color: var(--button-ink);
}

.lv-switch-option[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
}

.lv-switch-icon,
.lv-switch-icon svg {
  display: block;
  width: 15px;
  height: 15px;
}

.lv-icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Layout: the stage, and the list beside it at the stage's height. */

.lv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: stretch;
}

.lv-stage-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.lv-stage {
  position: relative;
  height: var(--lv-stage-height);
  container-type: size;
  overflow: hidden;
}

.lv-globe,
.lv-map {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity .35s ease, visibility 0s linear 0s;
}

.lv-globe {
  padding: 34px 8px 8px;
}

.lv-map {
  padding: 46px 18px 18px;
}

[data-view="map"] .lv-globe,
[data-view="globe"] .lv-map {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear .35s;
}

.lv-globe-canvas {
  display: block;
  cursor: grab;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
}

/* The globe fades in with its first frame (three.js arrives after the page has painted). */
.lv-globe-canvas[data-drawn] {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .lv-globe-canvas {
    transition: opacity .45s ease;
  }
}

.lv-globe[data-dragging] .lv-globe-canvas {
  cursor: grabbing;
}

.lv-map-box {
  position: relative;
  width: min(100%, calc((100cqh - 64px) * var(--lv-map-aspect)));
  aspect-ratio: var(--lv-map-aspect);
}

.lv-map-land {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.lv-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.lv-mode {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.lv-mode-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
}

.lv[data-mode="replay"] .lv-mode-dot {
  background: var(--visitors);
}

.lv[data-mode="offline"] .lv-mode-dot {
  background: var(--faint);
}

.lv-stage-note {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(360px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.lv[data-enhanced] .lv-stage-note {
  display: none;
}

.lv[data-stage="failed"] .lv-stage::after {
  content: "The map couldn't be drawn here. The list still updates.";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-size: 14px;
}

/* The card beside a located place. Positioned by the view, with transforms. */

.lv-card {
  position: absolute;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(260px, calc(100% - 16px));
  padding: 10px 12px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-menu);
  font-size: 13px;
  line-height: 1.4;
  transition: opacity .2s ease;
}

.lv-card[data-away="true"] {
  opacity: 0;
}

.lv-card[data-unplaced="true"] {
  top: auto;
  bottom: 14px;
  left: 16px;
}

.lv-card-place {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-weight: 620;
  font-size: 14px;
}

.lv-card-flag {
  width: 16px;
  height: 16px;
}

.lv-card-flag[hidden] {
  display: none;
}

.lv-card-path {
  margin-top: 4px;
  color: var(--ink-2);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.lv-card-line,
.lv-card-count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
}

/* The replay: play, a scrubber over 32 bars (coral ticks for sales), "Now" at the end. */

.lv-replay {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 12px 18px 10px;
  border-top: 1px solid var(--line-2);
}

.lv-play {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--button-bg);
  border-radius: var(--radius-control);
  background: var(--button-bg);
  color: var(--button-ink);
  cursor: pointer;
  transition: background-color .15s ease;
}

.lv-play:hover {
  background: var(--button-hover);
}

.lv-play .lv-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: none;
}

.lv-play .lv-icon-pause,
.lv[data-playing] .lv-play .lv-icon-play {
  display: none;
}

.lv[data-playing] .lv-play .lv-icon-pause {
  display: block;
}

.lv-play[disabled],
.lv:not([data-replay-ready]) .lv-play {
  opacity: .5;
  cursor: default;
}

.lv-scrub-wrap {
  min-width: 0;
}

.lv-scrub {
  position: relative;
  height: 40px;
  cursor: pointer;
  touch-action: none;
  border-radius: 4px;
  user-select: none;
}

.lv-scrub:focus-visible {
  outline-offset: 4px;
}

.lv-bars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.lv-bar {
  fill: var(--lv-bar);
  transition: fill .2s ease;
}

.lv-bar[data-current] {
  fill: var(--lv-bar-current);
}

.lv-bar-sale {
  fill: var(--revenue);
}

.lv-bar-live {
  fill: var(--live);
}

.lv-thumb {
  position: absolute;
  top: -5px;
  bottom: -3px;
  left: 98.5%;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ink);
  pointer-events: none;
}

.lv-thumb::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -2px;
  width: 10px;
  height: 7px;
  border-radius: 2px;
  background: var(--ink);
}

.lv:not([data-replay-ready]) .lv-thumb {
  opacity: 0;
}

.lv-scrub-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* The list: DataBull's rows (flag in a circle, the path in mono, "City · source"), in a
   panel exactly as tall as the stage; the rows scroll inside it. */

.lv-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  contain: size;
  overflow: hidden;
}

.lv-list-head {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line-2);
}

.lv-count {
  display: flex;
  align-items: baseline;
  gap: 0;
  color: var(--ink);
  font-size: 16px;
  font-weight: 620;
}

.lv-count-n {
  display: inline-block;
  margin-right: .1em;
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.lv-live-dot {
  position: relative;
  align-self: center;
  flex: none;
  width: 8px;
  height: 8px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--faint);
}

.lv-live-dot[data-on] {
  background: var(--live);
}

.lv-live-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--live);
  opacity: 0;
}

.lv-count-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13.5px;
}

.lv-rows {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.lv-rows:empty {
  display: none;
}

.lv-row {
  transition: transform .45s var(--ease-out);
}

.lv-row-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s ease;
}

.lv-row-button:hover {
  background: var(--surface-2);
}

.lv-row-button:focus-visible {
  outline-offset: -2px;
}

.lv-row-button[aria-pressed="true"] {
  background: var(--brand-tint);
  box-shadow: inset 2px 0 0 var(--lv-focus);
}

.lv-row[data-here] .lv-row-button {
  background: var(--surface-2);
}

/* The row's flag: the base `.flag` (app.css), drawn at the circle's size. */
.lv-flag {
  display: block;
  width: 30px;
  height: 30px;
}

/* No country: flag-icons' blank flag, quietened (and dimmed, not white, in the dark). */
.lv-flag[data-unknown] {
  opacity: .55;
}

:where(:root[data-theme="dark"]) .lv-flag[data-unknown] {
  filter: invert(.86);
}

@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) .lv-flag[data-unknown] {
    filter: invert(.86);
  }
}

.lv-row-main {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.lv-path,
.lv-place-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lv-place-name {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 540;
}

.lv-line {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lv-row-side {
  display: grid;
  justify-items: end;
  gap: 1px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.lv-paid {
  color: var(--revenue-ink);
  font-weight: 650;
}

.lv-ago,
.lv-place-count {
  color: var(--faint);
  white-space: nowrap;
}

.lv-place-count {
  color: var(--muted);
}

.lv-empty,
.lv-step-empty {
  padding: 36px 24px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.lv-step-empty {
  list-style: none;
}

.lv-replay-list {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.lv-replay-list[hidden] {
  display: none;
}

/* While replaying, the header counts the step's visitors and the live parts step back. */

.lv[data-replaying] .lv-live-dot {
  background: var(--visitors);
}

.lv[data-replaying] .lv-live-dot::after {
  display: none;
}

.lv[data-replaying] .lv-sales {
  display: none;
}

/* The last hour's sales, under the list. */

.lv-sales {
  flex: none;
  padding: 12px 20px 14px;
  border-top: 1px solid var(--line-2);
}

.lv-sales-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 560;
}

.lv-sale-rows {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lv-sale {
  display: grid;
  grid-template-columns: 8px auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 26px;
  font-size: 13px;
  border-radius: 4px;
}

.lv-sale-mark {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--revenue);
}

.lv-sale-amount {
  color: var(--revenue-ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lv-sale-what {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lv-sale-what .flag {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: -2px;
}

/* Map pins. Sized by --lv-pin-size; rings and bursts are pseudo-elements and children that
   only scale and fade. */

.lv-pins {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.lv-pin {
  position: absolute;
  width: 0;
  height: 0;
}

.lv-pin-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--lv-pin-size, 7px);
  height: var(--lv-pin-size, 7px);
  margin: calc(var(--lv-pin-size, 7px) / -2);
  border-radius: 50%;
  background: var(--lv-pin);
  box-shadow: 0 0 0 1.5px var(--lv-pin-edge), 0 0 0 6px var(--lv-pin-halo);
  pointer-events: auto;
  cursor: pointer;
}

.lv-pin-dot::before {
  /* A larger target than the dot. */
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}

.lv-pin-sale .lv-pin-dot {
  background: var(--lv-sale);
  box-shadow: 0 0 0 1.5px var(--lv-pin-edge), 0 0 0 6px var(--lv-sale-halo);
}

.lv-pin[data-focus] .lv-pin-dot {
  box-shadow: 0 0 0 3px var(--lv-pin-edge), 0 0 0 5px var(--lv-focus), 0 0 0 10px var(--lv-pin-halo);
}

.lv-pin::after,
.lv-pin::before {
  content: "";
  position: absolute;
  left: -28px;
  top: -28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent calc(100% - 3px), var(--lv-pin) calc(100% - 2.2px), var(--lv-pin) calc(100% - .6px), transparent 100%);
  opacity: 0;
  pointer-events: none;
}

.lv-pin::before {
  background: radial-gradient(circle closest-side, transparent calc(100% - 3px), var(--lv-focus) calc(100% - 2.2px), var(--lv-focus) calc(100% - .6px), transparent 100%);
}

.lv-burst {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.lv-burst-ring,
.lv-burst-flash,
.lv-burst-ray {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
}

.lv-burst-ring {
  width: 104px;
  height: 104px;
  margin: -52px;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent calc(100% - 3.4px), var(--lv-sale) calc(100% - 2.8px), var(--lv-sale) calc(100% - .6px), transparent 100%);
}

.lv-burst-flash {
  width: 22px;
  height: 22px;
  margin: -11px;
  border-radius: 50%;
  background: var(--lv-sale);
}

.lv-burst-ray {
  width: 14px;
  height: 2.5px;
  margin-top: -1.25px;
  border-radius: 1px;
  background: var(--lv-sale);
  transform-origin: 0 50%;
}

/* The page's own entrances and updates. */

@media (prefers-reduced-motion: no-preference) {
  .lv-row.is-new {
    animation: lv-row-in .5s var(--ease-out) both;
  }

  .lv-row.is-new .lv-row-button {
    animation: lv-row-flash 2.6s ease both;
  }

  .lv-path.is-changed,
  .lv-count-n.is-changed {
    animation: lv-text-in .45s var(--ease-out) both;
  }

  .lv-sale.is-new {
    animation: lv-sale-flash 2.8s ease both;
  }

  .lv-live-dot[data-on]::after {
    animation: tally-ping 2s var(--ease-out) infinite;
  }

  .lv[data-mode="live"] .lv-mode-dot {
    animation: lv-breathe 2.4s var(--ease-in-out) infinite;
  }

  .lv-thumb {
    transition: left .22s var(--ease-out);
  }

  .lv-pin.is-new::after {
    animation: lv-ring 1.9s var(--ease-out) var(--lv-delay, 0ms) both;
  }

  .lv-pin.is-new .lv-pin-dot {
    animation: lv-pin-in .5s cubic-bezier(.34, 1.56, .64, 1) var(--lv-delay, 0ms) both;
  }

  .lv-pin.is-locating::before {
    animation: lv-locate 1.2s var(--ease-out) both;
  }

  .lv-burst-ring {
    animation: lv-burst-ring 1.6s var(--ease-out) both;
  }

  .lv-burst-ring-late {
    animation-delay: .32s;
  }

  .lv-burst-flash {
    animation: lv-burst-flash .6s ease-out both;
  }

  .lv-burst-ray {
    animation: lv-ray 1.4s var(--ease-out) .05s both;
  }

  .lv-card {
    animation: lv-card-in .25s var(--ease-out) both;
  }
}

@keyframes lv-row-in {
  from {
    opacity: 0;
    transform: translate3d(0, -10px, 0);
  }
}

@keyframes lv-row-flash {
  0%,
  35% {
    background-color: var(--live-tint);
  }
}

@keyframes lv-sale-flash {
  0%,
  40% {
    background-color: var(--revenue-bar);
  }
}

@keyframes lv-text-in {
  from {
    opacity: 0;
    transform: translate3d(0, 4px, 0);
  }
}

@keyframes lv-breathe {
  50% {
    opacity: .35;
  }
}

@keyframes lv-ring {
  from {
    opacity: .95;
    transform: scale(.14);
  }
  to {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes lv-pin-in {
  from {
    transform: scale(0);
  }
}

@keyframes lv-locate {
  from {
    opacity: 0;
    transform: scale(1);
  }
  40% {
    opacity: .9;
  }
  to {
    opacity: 0;
    transform: scale(.3);
  }
}

@keyframes lv-burst-ring {
  from {
    opacity: 1;
    transform: scale(.08);
  }
  to {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes lv-burst-flash {
  from {
    opacity: .65;
    transform: scale(.4);
  }
  to {
    opacity: 0;
    transform: scale(1.4);
  }
}

@keyframes lv-ray {
  from {
    opacity: 1;
    transform: rotate(var(--lv-angle)) translate3d(7px, 0, 0) scaleX(.4);
  }
  to {
    opacity: 0;
    transform: rotate(var(--lv-angle)) translate3d(34px, 0, 0) scaleX(1);
  }
}

@keyframes lv-card-in {
  from {
    opacity: 0;
  }
}

/* Narrower screens: the list goes under the stage, at a fixed height of its own. */

@media (max-width: 1100px) {
  .lv {
    --lv-stage-height: 480px;
  }

  .lv-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

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

  .lv-list {
    contain: none;
    height: 520px;
  }
}

@media (max-width: 640px) {
  .lv {
    --lv-stage-height: 400px;
  }

  .lv-head .dash-sub {
    display: none;
  }

  .lv-switch-option {
    height: 32px;
    padding: 0 11px;
  }

  .lv-globe {
    padding: 30px 0 0;
  }

  /* A phone's stage is too narrow for the whole world at a useful size: the map is drawn
     larger and pans sideways (the page itself never scrolls sideways). */
  .lv-map {
    padding: 40px 10px 12px;
    justify-items: start;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .lv-map::-webkit-scrollbar {
    display: none;
  }

  .lv-map-box {
    width: min(calc((100cqh - 52px) * var(--lv-map-aspect)), 180cqw);
  }

  .lv-replay {
    gap: 12px;
    padding: 12px 14px 10px;
  }

  .lv-list-head {
    padding: 16px 16px 10px;
  }

  .lv-rows {
    padding: 4px 6px;
  }

  .lv-sales {
    padding: 10px 16px 12px;
  }
}
