/* =========================================================================
   ANALYTICS: the admin Analytics page (features/analytics/*): the agency
   website's visitors, heatmaps, VSL, leads and Meta ads. Prefix an-.

   v2 (11 Oct 2026): Framer's analytics in our design system. No page head and
   no cards: the toolbar row holds the views (.segmented) and the scope group
   (#anScope: labelled selects, the range dropdown, the date chip); the page
   is hairline bands built from the shared stats primitives in components.css
   (.stat-strip, .stat-band, .stat-section, .bar-list, .lsel). Tables are
   .stat-table, empty / error are emptyState / errorState, drawers are
   drawerShell + the lead drawer's .dw-*.
   This file holds what is really Analytics' own: the page frame and its
   refetch states, the scope group and its menus, the calendar popover, the
   live dot, naked row glyphs, the install line, the "latest activity" dots
   and the shared line chart (.anc-*, anChart.js).
   (The heatmap canvas, the ad thumbnail and the ad viewer are in
   analytics-panels.css.)
   ========================================================================= */

/* ---------- the page frame: white, full width ---------- */
.an { padding: 0 var(--space-6) var(--space-8); }
.an-body { position: relative; }
.an-pane { min-width: 0; transition: opacity var(--dur) var(--ease); }
/* a scope change keeps the frame: the old pane dims while the new one mounts hidden, then they swap */
.an-pane.is-stale { opacity: 0.5; pointer-events: none; }
.an-pane.is-pending { position: absolute; inset: 0 0 auto 0; visibility: hidden; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .an-pane { transition: none; } }
/* a note sits on the page (no card), closed by the band hairline */
.an-pane > .stat-note { padding: var(--space-4) 0; border-bottom: 1px solid var(--border-faint); }
.an-pane > .stat-note + .stat-note { border-top: 0; }
.an-pane > .stat-note .an-code { max-width: 640px; }
/* the empty and error states sit in the middle of the page, under the toolbar */
.an-pane > .empty-state, .an-pane > [role="alert"] { padding-top: var(--space-10); }
.an-empty-code { width: min(640px, 100%); margin: var(--space-4) auto 0; }   /* the whole line beside its Copy */
.an-empty-code .an-code code { text-align: left; }   /* the line reads from the left; Copy sits inside on the right */
.an-empty-code + .lead-empty-cta { margin-top: var(--space-4); }

/* ---------- the scope group in the toolbar (anScope.js) ---------- */
.an-scope { display: flex; align-items: center; gap: var(--space-2); min-width: 0; margin-left: auto; }
.an-scope-slot { display: contents; }
.an-scope .filter-dd[hidden], .an-scope [hidden] { display: none; }
.an-range-btn > svg:last-child, .an-dates-btn > svg { width: 16px; height: 16px; color: var(--text-soft); }   /* even, as every .btn icon (16 Nov): 15 sat half a pixel under the label */
.an-range-ico { display: none; }
.an-dates-label, .an-range-label, .an-range-dates { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* a custom range: "Custom" beside the date chip, its dates wherever the chip has folded away (the same three rules) */
.an-range-dates { display: none; }
@media (max-width: 1439px) {
  .an-range-btn.is-custom .an-range-label { display: none; }
  .an-range-btn.is-custom .an-range-dates { display: inline; }
}
@media (max-width: 1599px) {
  .an-scope:has(> .an-scope-slot > *) .an-range-btn.is-custom .an-range-label { display: none; }
  .an-scope:has(> .an-scope-slot > *) .an-range-btn.is-custom .an-range-dates { display: inline; }
}
@media (max-width: 1759px) {
  .an-scope.is-crowded .an-range-btn.is-custom .an-range-label { display: none; }
  .an-scope.is-crowded .an-range-btn.is-custom .an-range-dates { display: inline; }
}
.an-more-dd { display: none; }
.an-scope [data-an-range-dd][hidden], .an-scope [data-an-dates-dd][hidden] { display: none; }   /* (Ask: its own period chip) */
.an-scope-more { position: relative; }
/* a control reading its list (Page asks for the pages seen in the period): the shared spinner where its glyph sits */
.an-scope [aria-busy="true"] { cursor: progress; }
.an-scope .lsel[aria-busy="true"] .lsel-v > svg, .an-scope .an-scope-more[aria-busy="true"] > svg { display: none; }
.an-busy-spin { width: 14px; height: 14px; border-width: 1.5px; }
/* how many filters are folded in: a count is quiet, never the accent (13 Oct 2026) */
.an-scope-count { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; padding: 0 var(--space-1); border-radius: var(--radius-full); background: var(--surface-hover-strong); color: var(--text-strong); font-size: var(--text-2xs); font-weight: var(--fw-semibold); line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
@media (max-width: 1439px) { .an-scope .an-dates-dd { display: none; } }
/* a tab's own select (Video, Ad account) takes the chip's room up to 1600px: its dates stay on the range button's title */
@media (max-width: 1599px) { .an-scope:has(> .an-scope-slot > *) .an-dates-dd { display: none; } }
/* below 1024px (the tablet rail) Page and the tab's select fold into Filters; the range stays */
@media (max-width: 1023px) {
  .an-scope .an-scope-slot, .an-scope [data-an-page-dd] { display: none; }
  .an-scope .an-more-dd { display: block; }
}
@media (max-width: 1279px) { .an-scope:not(.is-crowded) .lsel-k { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; } }
@media (min-width: 1280px) and (max-width: 1439px) {   /* (with a tab's own select the keys go a width sooner) */
  .an-scope:not(.is-crowded):has(> .an-scope-slot > *) .lsel-k { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; }
}
/* crowded (anScope.js: a tab's own select AND Page, VSL with 2+ videos): the date chip and the Page and Compare keys
   go first, then Page folds into Filters, so the views never fold at 1024px and up */
@media (max-width: 1759px) {
  .an-scope.is-crowded .an-dates-dd { display: none; }
  .an-scope.is-crowded [data-an-page-dd] .lsel-k { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; padding: 0; }
}
@media (max-width: 1439px) {
  .an-scope.is-crowded [data-an-page-dd] { display: none; }
  .an-scope.is-crowded .an-more-dd { display: block; }
}

/* its menus, on the shared .filter-menu surface (a FilterSheet on a phone) */
.an-menu { min-width: 220px; max-height: min(420px, calc(100vh - 160px)); overflow-y: auto; }
.an-menu.is-right, .an-cal.is-right { left: auto; right: 0; }
.an-menu--range, .an-menu--compare { min-width: 300px; }
.an-menu--pages { min-width: 260px; max-width: min(380px, calc(100vw - var(--space-8))); }
.an-menu .filter-opt { flex: none; text-align: left; }
.an-menu-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-menu .filter-opt .opt-count { white-space: nowrap; }
.an-menu .filter-opt.is-drill > svg { color: var(--text-soft); }
.an-menu .filter-opt[aria-disabled="true"] { opacity: 0.5; cursor: default; }
/* a row with its own remove x after it (popMenu item.remove: Add lead's own source options) */
.an-menu-row { display: flex; align-items: center; gap: var(--space-0-5); flex: none; }
.an-menu-row > .filter-opt { flex: 1 1 auto; min-width: 0; }
.an-menu-row > .an-menu-remove { margin-right: var(--space-1); }
.an-menu-remove svg { margin: 0; color: inherit; }
.an-menu-remove:focus-visible { outline: none; box-shadow: var(--ring-primary); }

/* the calendar popover (the Leads .sort-menu + .sort-cal, calendar only) */
.an-cal { width: 300px; }
.an-cal-foot { margin: var(--space-2) 0 0; padding-top: var(--space-2); border-top: 1px solid var(--border-faint); font-size: var(--text-xs); color: var(--text-soft); text-align: center; }
.an-cal .sort-cal .day:focus-visible, .an-cal .cal-nav:focus-visible { outline: none; box-shadow: var(--ring-primary); }

/* ---------- Live visitors: the blue dot (Framer); a soft ring pulses while the site is recording ---------- */
.an-live-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--gray-300); }
.an-live-dot.is-on { background: var(--info-600); animation: an-live 2s var(--ease-exit) infinite; }
@keyframes an-live { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--info-600) 45%, transparent); } 100% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--info-600) 0%, transparent); } }
@media (prefers-reduced-motion: reduce) { .an-live-dot.is-on { animation: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--info-600) 20%, transparent); } }

/* a naked glyph beside a row label (channels, tracked events, pages): the Attio rule, 16px in --text-soft */
.an-ico { display: inline-flex; flex: none; color: var(--text-soft); }
.an-ico svg { width: 16px; height: 16px; }
.bar-row-main .src-ico--device { color: var(--text-soft); }

/* ---------- table cells ---------- */
.an-cell { display: flex; align-items: center; gap: var(--space-2-5); min-width: 0; }
.an-cell-txt { display: flex; flex-direction: column; min-width: 0; }
.an-cell-name { font-weight: var(--fw-medium); color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-cell-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-cell-label b { font-weight: var(--fw-medium); color: var(--text-strong); }
.an-cell-sub { font-size: var(--text-xs); color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-muted { color: var(--text-soft); }
.an-nowrap { white-space: nowrap; }
/* the column that takes the slack and ellipsises its label (a table cell only shrinks below its content at max-width 0) */
.stat-table .an-grow { width: 100%; max-width: 0; }
.stat-table .an-grow ~ th, .stat-table .an-grow ~ td { white-space: nowrap; }   /* the columns after it keep their figures on one line */
/* rows that open something: without a card around them the row's hover runs just past the text */
.an .stat-table--rows { width: calc(100% + 2 * var(--space-2)); margin: 0 calc(-1 * var(--space-2)); }
.an .stat-table--rows th:first-child, .an .stat-table--rows td:first-child { padding-left: var(--space-2); }
.an .stat-table--rows th:last-child, .an .stat-table--rows td:last-child { padding-right: var(--space-2); }
.an .stat-table--rows tbody tr { border-radius: var(--radius-sm); }

/* the leads table in a narrow main column (a tablet's, a narrow window's): Lead · Sent · Came from · Status. The
   campaign line, the video watched and the visits wait in the journey drawer, so the name keeps its room (a phone
   also drops Sent: .is-wide) */
@container main-col (max-width: 720px) {
  .an .stat-table .an-mid { display: none; }
  .an-from .an-cell-sub { display: none; }
}

/* ---------- latest activity: a 7px dot per kind (the size of the .stage dots) ---------- */
.an-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--gray-300); }
.an-dot.is-lead { background: var(--success-600); }
.an-dot.is-form { background: var(--warning-600); }
.an-dot.is-video { background: var(--info-600); }
.an-dot.is-rage { background: var(--danger-600); }

/* ---------- the tracking line to copy (in a note's actions, or under the empty state) ---------- */
.an-code { display: flex; align-items: center; gap: var(--space-2); flex: 1 1 auto; min-width: 0; max-width: 100%; padding: var(--space-1-5) var(--space-1-5) var(--space-1-5) var(--space-3); border-radius: var(--radius-md); background: var(--surface-sunk); text-align: left; }
.an-code code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: var(--text-xs); color: var(--text); }
.an-code [data-an-copy] { min-width: 96px; justify-content: center; }   /* fits "Copied" too, so the field never shifts */

/* the journey and ad drawers: the foot's one action runs full width */
.an-drawer .drawer-foot .btn { width: 100%; }
/* a lead no visit matched: the note's glyph at the drawer's icon size */
.an-drawer .dw-tl-error { align-items: flex-start; padding: var(--space-4) 0; line-height: 1.5; }
.an-drawer .dw-tl-error > svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

/* ---------- Revenue (revenue.js): a stopped line reads quieter; the line and products sheets ---------- */
.an .stat-table tr.rv-ended td { color: var(--text-muted); }
.rv-form { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); }
.rv-form .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.rv-form .field-desc { margin: calc(-1 * var(--space-2)) 0 0; }
.rv-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.rv-foot .rv-delete { margin-right: auto; color: var(--danger-700); }
.rv-prods { display: flex; flex-direction: column; gap: var(--space-2); }
.rv-prod, .rv-prod-head { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) 28px; gap: var(--space-2); align-items: center; }
.rv-prod-head { font-size: var(--text-xs); font-weight: var(--fw-medium); color: var(--text-muted); margin-bottom: calc(-1 * var(--space-2)); }
.rv-prod-add { align-self: flex-start; }

/* ---------- the line chart (anChart.js) ---------- */
.anc-band { padding: var(--space-5) 0 var(--space-6); }   /* a .stat-section that holds a chart */
.stat-strip + .anc-band { border-top: 0; }
.anc { position: relative; }
.anc-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-4); margin: 0 0 var(--space-3); padding: 0; list-style: none; font-size: var(--text-xs); color: var(--text-muted); }
.anc-legend[hidden] { display: none; }
.anc-legend li { display: inline-flex; align-items: center; gap: var(--space-1-5); }
.anc-ring { width: 9px; height: 9px; flex: none; border-radius: 50%; border: 1.5px solid var(--chart-line); }
.anc-ring--dotted { border-style: dotted; }
.anc-ring--compare { border-color: var(--chart-line-compare); }
.anc-ring--mark { border-color: var(--success-600); background: var(--success-600); }
.anc-plot { position: relative; height: var(--anc-h, 240px); touch-action: pan-y; outline: none; }
.anc-plot:focus-visible { box-shadow: var(--ring-primary); border-radius: var(--radius-sm); }
.anc-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.anc-max { position: absolute; top: 0; left: 0; font-size: var(--text-xs); color: var(--text-soft); font-variant-numeric: tabular-nums; line-height: 1; pointer-events: none; }
.anc-base { stroke: var(--border-faint); stroke-width: 1; shape-rendering: crispEdges; }
.anc-area-a { stop-color: var(--chart-line); stop-opacity: 0.1; }
.anc-area-b { stop-color: var(--chart-line); stop-opacity: 0; }
.anc-line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.anc-line--dotted { stroke-dasharray: 0 4; }   /* round caps on zero-length dashes draw dots */
.anc-line--compare { stroke: var(--chart-line-compare); stroke-width: 1.5; }
.anc-mark { fill: var(--success-600); stroke: var(--surface); stroke-width: 2; }
.anc-pin { fill: var(--surface); stroke: var(--chart-line); stroke-width: 1.5; }
.anc-cross { stroke: var(--border-strong); stroke-width: 1; shape-rendering: crispEdges; opacity: 0; }
.anc-dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; opacity: 0; }
.anc-dot--hollow { fill: var(--surface); stroke: var(--chart-line); stroke-width: 1.5; }
.anc-dot--compare { fill: var(--chart-line-compare); }
.anc.is-hover .anc-cross, .anc.is-hover .anc-dot { opacity: 1; }
/* a chart whose points pick something (spec.onPick: the VSL curve seeks its player), and the playhead it follows */
.anc--pick .anc-plot { cursor: pointer; }
.anc-head { stroke: var(--info-600); stroke-width: 1.5; }
.anc-head-dot { fill: var(--info-600); stroke: var(--surface); stroke-width: 2; }
.anc-ends { display: flex; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-soft); font-variant-numeric: tabular-nums; }
.anc-tip { position: absolute; top: var(--space-2); left: 0; z-index: var(--z-popover); min-width: 184px; padding: var(--space-2-5) var(--space-3); background: var(--chart-tip-bg); border: 1px solid var(--chart-tip-border); border-radius: var(--radius-lg); box-shadow: var(--chart-tip-shadow); pointer-events: none; opacity: 0; transform: translateY(2px); transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.anc.is-hover .anc-tip { opacity: 1; transform: none; }
.anc-tip-head { padding-bottom: var(--space-2); margin-bottom: var(--space-1); border-bottom: 1px solid var(--border-faint); font-size: var(--text-xs); color: var(--text-soft); white-space: nowrap; }
.anc-tip-row { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; align-items: center; gap: var(--space-2); height: 24px; font-size: var(--text-sm); color: var(--text-muted); white-space: nowrap; }
.anc-tip-row > b { font-weight: var(--fw-semibold); color: var(--text-strong); font-variant-numeric: tabular-nums; }
.anc-tip-sep { height: 1px; margin: var(--space-1) 0; background: var(--border-faint); }
.anc-sk { display: block; width: 100%; height: var(--anc-h, 240px); border-radius: var(--radius-md); }
.anc .anc-series { clip-path: inset(0 0 0 0); }
.anc.is-revealing .anc-series { animation: anc-reveal calc(var(--dur-slow) * 2) var(--ease-enter) both; }
@keyframes anc-reveal { from { clip-path: inset(0 100% 0 0); } }
@media (prefers-reduced-motion: reduce) { .anc.is-revealing .anc-series { animation: none; } .anc-tip { transition: none; } }

/* ---------- narrower ---------- */
@media (max-width: 900px) {
  .an-menu.is-right, .an-cal.is-right { left: auto; right: 0; }
}
@media (max-width: 640px) {
  .an { padding: 0 max(var(--space-4), var(--safe-right)) var(--space-6) max(var(--space-4), var(--safe-left)); }
  .anc-plot, .anc-sk { --anc-h: 180px; }
  .an-pane > .empty-state, .an-pane > [role="alert"] { padding-top: var(--space-6); }
  /* the toolbar row stays on a phone (it is the only way between the views): touch-height buttons, as Content's */
  #mainToolbar[data-route="analytics"] .an-tabseg button,
  #mainToolbar[data-route="analytics"] .an-tabseg .rt-more { height: 44px; padding: 0 var(--space-2-5); }
  /* #anScope moved beside the crumb (mobileToolbar.js): two 44px discs, as Leads' Sorted-by + Filter */
  .topbar-right .an-scope.tb-moved { display: flex; gap: var(--space-2); margin-left: 0; }
  .topbar-right .an-scope .an-scope-slot,
  .topbar-right .an-scope [data-an-page-dd],
  .topbar-right .an-scope .an-dates-dd { display: none; }
  .topbar-right .an-scope .an-more-dd { display: block; }
  .topbar-right .an-scope .an-more-dd[hidden] { display: none; }
  .topbar-right .an-range-btn, .topbar-right .an-scope-more { display: inline-flex; width: 44px; min-width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: var(--radius-full); }
  .topbar-right .an-range-btn .an-range-label, .topbar-right .an-range-btn > svg:last-child,
  .topbar-right .an-scope .an-range-btn.is-custom .an-range-dates { display: none; }
  .topbar-right .an-range-ico { display: inline-flex; }
  .topbar-right .an-range-ico svg { width: 19px; height: 19px; color: var(--text); }
  .an-menu.filter-sheet { max-width: none; max-height: 80vh; }
  .an-cal.filter-sheet { width: auto; }
  /* the leads table keeps Lead · Came from · Status (the campaign line folds away in a narrow column, above) */
  .an-from .an-cell-txt { max-width: 6.5em; }
  .an-code code { white-space: normal; overflow-wrap: anywhere; }
  .an .stat-table--rows { width: 100%; margin: 0; }
  .an .stat-table--rows th:first-child, .an .stat-table--rows td:first-child { padding-left: 0; }
  .an .stat-table--rows th:last-child, .an .stat-table--rows td:last-child { padding-right: 0; }
}
/* a phone narrower than 390px: the five views keep a little less room each, rather than three folding into "+3 more"
   (they need 347px at the usual padding: 327 at 8px, 307 at 6px) */
@media (max-width: 389px) {
  #mainToolbar[data-route="analytics"] .an-tabseg button { padding: 0 var(--space-2); }
}
@media (max-width: 374px) {
  #mainToolbar[data-route="analytics"] .an-tabseg button { padding: 0 var(--space-1-5); }
}
