/* pages/analytics.css — premium, theme-safe analytics dashboard. */

.an-shell {
  width: 100%;
  min-width: 0;
  max-width: 1280px;
  margin-inline: auto;
  padding: var(--space-20) var(--space-24) var(--space-32);
  display: grid;
  gap: var(--space-20);
}

.an-period {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
}

.an-period > span {
  color: var(--text-tertiary);
  font-size: var(--fs-secondary);
  font-weight: var(--fw-medium);
}

.an-period__options {
  display: inline-flex;
  max-width: 100%;
  padding: var(--space-4);
  gap: var(--space-4);
  overflow-x: auto;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-12);
}

.an-period__options button {
  min-width: 58px;
  min-height: 36px;
  padding-inline: var(--space-10);
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius-8);
  font: inherit;
  font-size: var(--fs-secondary);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  cursor: pointer;
}

.an-period__options button:hover { color: var(--text-primary); background: var(--bg-hover); }
.an-period__options button[aria-pressed="true"] {
  color: var(--accent-soft-text);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.an-period__options button:focus-visible { outline-offset: -2px; }

/* Snapshot freshness / partial-data state */
.an-statusbar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  background: var(--ok-soft-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-12);
  box-shadow: var(--shadow-sm);
}

.an-statusbar__mark {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: var(--radius-pill);
  background: var(--ok);
  box-shadow: 0 0 0 4px var(--ok-soft-bg);
}

.an-statusbar__copy {
  min-width: 0;
  display: grid;
  gap: var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--fs-secondary);
}

.an-statusbar__copy strong {
  color: var(--text-primary);
  font-size: var(--fs-body);
}

.an-statusbar__partial-copy { color: var(--warn); }
.an-statusbar__refresh { margin-inline-start: auto; flex: 0 0 auto; }

.an-statusbar--partial,
.an-statusbar--stale { background: var(--warn-soft-bg); }

.an-statusbar--partial .an-statusbar__mark,
.an-statusbar--stale .an-statusbar__mark {
  background: var(--warn);
  box-shadow: 0 0 0 4px var(--warn-soft-bg);
}

/* KPI tiles */
.an-tiles {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-12);
}

.an-tile {
  min-width: 0;
  min-height: 116px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-sm);
  padding: var(--space-16);
  display: grid;
  align-content: center;
  gap: var(--space-6);
  position: relative;
  overflow: hidden;
}

.an-tile--accent {
  border-color: var(--accent-soft-border);
  background: linear-gradient(145deg, var(--bg-surface), var(--accent-soft-bg));
}

.an-tile--accent::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 3px;
  background: var(--accent);
}

.an-tile__label {
  min-width: 0;
  font-size: var(--fs-label);
  color: var(--text-tertiary);
  letter-spacing: 0.035em;
  font-weight: var(--fw-medium);
  overflow-wrap: anywhere;
}

.an-tile__value { font-size: var(--fs-title); font-weight: var(--fw-bold); color: var(--text-primary); font-variant-numeric: tabular-nums; line-height: 1.1; overflow-wrap: anywhere; }
.an-tile__sub { min-width: 0; font-size: var(--fs-small); color: var(--text-muted); overflow-wrap: anywhere; }
.an-tile--skel { gap: var(--space-10); }
.an-tile--skel .skeleton-row { height: 22px; }
.an-skeleton-label { width: 76%; }
.an-skeleton-value { width: 56%; }

/* Cards and grids */
.an-card {
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-sm);
  padding: var(--space-20);
}

.an-card__head {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-16);
  margin-bottom: var(--space-16);
  flex-wrap: wrap;
}

.an-card__title {
  margin: 0 0 var(--space-12);
  font-size: var(--fs-body);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
}

.an-card__head .an-card__title { margin: 0; }
.an-card__hint { margin: var(--space-4) 0 var(--space-16); color: var(--text-tertiary); font-size: var(--fs-secondary); }
.an-card__head .an-card__hint { margin-bottom: 0; }

.an-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-20);
}

.an-grid > * { min-width: 0; }
.an-grid--partial > :last-child:nth-child(odd) { grid-column: 1 / -1; }

.an-skeleton-chart {
  min-height: 248px;
  display: grid;
  align-items: center;
}

.an-skeleton-chart .skeleton-row {
  display: block;
  height: 180px;
  border-radius: var(--radius-12);
}

.an-page-error { margin-top: var(--space-12); }

.an-unavailable {
  min-height: 132px;
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-16);
  background: var(--warn-soft-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-12);
  color: var(--text-secondary);
}

.an-unavailable__mark {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  color: var(--warn);
  font-weight: var(--fw-heavy);
}

.an-unavailable strong { color: var(--text-primary); }
.an-unavailable p { margin: var(--space-4) 0 0; color: var(--text-tertiary); }
.an-card .state-empty { min-height: 148px; padding: var(--space-24) var(--space-16); }

/* Legend */
.an-legend {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-16);
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

.an-lg { display: inline-flex; align-items: center; gap: var(--space-6); white-space: nowrap; }
.an-dot { width: 9px; height: 9px; border-radius: var(--radius-4); display: inline-block; }

/* Interactive SVG trend chart */
.an-chart-wrap { min-width: 0; max-width: 100%; position: relative; }

.an-svg {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  overflow: visible;
  border-radius: var(--radius-8);
}

.an-svg:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.an-grid-line { stroke: var(--border-subtle); stroke-width: 1; }
.an-ax-y { fill: var(--text-muted); font-size: var(--fs-micro); text-anchor: end; font-variant-numeric: tabular-nums; }
.an-ax-x { fill: var(--text-muted); font-size: var(--fs-micro); text-anchor: middle; font-variant-numeric: tabular-nums; }
.an-area { stroke: none; }
.an-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.an-end { stroke: var(--bg-surface); stroke-width: 1.5; }
.an-cross { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.an-hot { stroke: var(--bg-surface); stroke-width: 2; }

.an-chart-help {
  margin: var(--space-8) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.an-tooltip {
  position: absolute;
  top: var(--space-6);
  max-width: calc(100% - var(--space-8));
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  box-shadow: var(--shadow-md);
  padding: var(--space-10) var(--space-12);
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
  display: grid;
  gap: var(--space-6);
  min-width: 150px;
  z-index: 2;
  overflow-wrap: anywhere;
}

.an-tooltip strong { color: var(--text-primary); font-size: var(--fs-secondary); font-variant-numeric: tabular-nums; }
.an-tooltip span { min-width: 0; display: flex; align-items: center; gap: var(--space-6); flex-wrap: wrap; }
.an-tooltip b { margin-left: auto; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.an-tooltip i { width: 8px; height: 8px; border-radius: var(--radius-pill); display: inline-block; flex: 0 0 auto; }
.an-tooltip__muted { color: var(--text-muted); }

/* Accessible chart table fallback */
.an-chart-data {
  margin-top: var(--space-16);
  border-top: 1px solid var(--border-subtle);
}

.an-chart-data summary {
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  cursor: pointer;
  color: var(--accent-soft-text);
  font-weight: var(--fw-medium);
}

.an-chart-data summary:hover { text-decoration: underline; text-underline-offset: 3px; }

.an-chart-data summary::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-inline-end: var(--space-8);
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform var(--dur-fast) var(--ease-standard);
}

.an-chart-data[open] summary::before { transform: rotate(45deg); }

.an-table-scroll {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-12);
}

.an-table-scroll:focus-visible { outline-offset: 3px; }

.an-data-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

.an-data-table th,
.an-data-table td {
  padding: var(--space-10) var(--space-12);
  border-bottom: 1px solid var(--border-subtle);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.an-data-table th:first-child { text-align: left; }
.an-data-table thead th { color: var(--text-tertiary); background: var(--bg-elevated); font-weight: var(--fw-medium); }
.an-data-table tbody th { color: var(--text-primary); font-weight: var(--fw-medium); }
.an-data-table tbody tr:last-child > * { border-bottom: 0; }

/* Horizontal bars */
.an-bars { min-width: 0; display: grid; gap: var(--space-10); }

.an-bar-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(92px, 152px) minmax(72px, 1fr) auto;
  align-items: center;
  gap: var(--space-12);
}

.an-bar-row__label {
  min-width: 0;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-bar-row__track {
  min-width: 0;
  height: 9px;
  background: var(--bg-input);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.an-bar-row__track--segments { display: flex; }
.an-bar-row__track--segments .an-bar-row__fill { border-radius: 0; }
.an-bar-row__fill { display: block; height: 100%; border-radius: var(--radius-pill); min-width: 3px; }

.an-bar-row__val {
  min-width: 0;
  max-width: 100%;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-secondary);
  color: var(--text-primary);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.an-bar-row__val small { color: var(--text-muted); font-weight: var(--fw-normal); margin-left: var(--space-6); }
.an-activation-funnel .an-bar-row__val small { margin-left: var(--space-8); }

/* Purposeful zero-data state */
.an-empty-overview {
  min-height: 320px;
  padding: var(--space-48) var(--space-24);
  background: linear-gradient(145deg, var(--bg-surface), var(--accent-soft-bg));
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius-16);
  box-shadow: var(--shadow-sm);
}

.an-empty-overview__mark {
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-16);
  background: var(--accent-soft-bg);
  color: var(--accent-soft-text);
  font-size: var(--fs-title);
  font-weight: var(--fw-bold);
}

@media (max-width: 900px) {
  .an-grid { grid-template-columns: minmax(0, 1fr); }
  .an-grid--partial > :last-child:nth-child(odd) { grid-column: auto; }
}

@media (min-width: 1800px) {
  .an-tiles { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .an-shell { padding: var(--space-12); gap: var(--space-16); }
  .an-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-card { padding: var(--space-16); }
  .an-statusbar { align-items: flex-start; flex-wrap: wrap; }
  .an-statusbar__copy { flex: 1 1 220px; }
  .an-card__head { gap: var(--space-12); }
}

@media (max-width: 560px) {
  .an-period { align-items: flex-start; flex-direction: column; }
  .an-period__options { width: 100%; }
  .an-period__options button { flex: 1 0 58px; }

  .an-bar-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: var(--space-6) var(--space-12);
  }
  .an-bar-row__label { grid-column: 1; grid-row: 1; }
  .an-bar-row__val { grid-column: 2; grid-row: 1; }
  .an-bar-row__track { grid-column: 1 / -1; grid-row: 2; }
  .an-chart-help { line-height: 1.45; }
  .an-empty-overview { min-height: 260px; padding: var(--space-32) var(--space-16); }
}

@media (max-width: 420px) {
  .an-statusbar__refresh { width: 100%; margin-inline-start: 0; }
  .an-tile { min-height: 108px; padding: var(--space-12); }
  .an-card { border-radius: var(--radius-12); padding: var(--space-12); }
  .an-tooltip { top: var(--space-4); }
}

@media (max-width: 359px) {
  .an-tiles { grid-template-columns: minmax(0, 1fr); }
}
