/* ==========================================================
   PHASE 5 — Website Analytics
   Builds on global.css and admin.css (shell, dashboard-topline,
   stat cards, skeletons, panels, dashboard-error). Only
   analytics-specific pieces live here: the range tabs, live-now
   panel, hand-rolled SVG trend charts, and the bar-list rows used
   for top pages / sources / devices / browsers / landing pages.

   No charting library is used — charts are small inline SVGs built
   from real aggregated data, matching "no giant charts, no clutter,
   premium agency analytics dashboard" from the design brief.
   ========================================================== */

.analytics-topline-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- Date range tabs ---------- */
.range-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.range-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.range-tab:hover:not(.is-active) {
  background: var(--surface);
  color: var(--text);
}

.range-tab.is-active {
  background: var(--primary);
  color: var(--white);
}

/* ---------- Metric cards (6-up instead of the dashboard's 3) ---------- */
.analytics-metrics-grid {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1180px) {
  .analytics-metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .analytics-metrics-grid { grid-template-columns: 1fr; }
}

.stat-value.stat-value-muted {
  font-size: 17px;
  color: #A79FBE;
  font-style: italic;
  font-weight: 700;
}

/* ---------- Live Now panel ---------- */
.live-panel {
  margin-bottom: 22px;
}

.live-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.live-dot.is-active {
  background: var(--success);
  box-shadow: 0 0 0 4px #E9F8F1;
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 4px #E9F8F1; }
  50% { box-shadow: 0 0 0 7px #E9F8F1; }
}

.live-updated {
  font-size: 12px;
  color: var(--muted);
}

.live-recent-empty {
  font-size: 13.5px;
  color: var(--muted);
  padding: 6px 0 2px;
}

.live-recent-list {
  display: none;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}

.live-recent-list.visible { display: flex; }

.live-recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}

.live-recent-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.live-recent-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 3px 8px;
  border-radius: 999px;
}

.live-recent-page {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-recent-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- Charts grid ---------- */
.analytics-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 22px 0;
}

@media (max-width: 900px) {
  .analytics-charts-grid { grid-template-columns: 1fr; }
}

.chart-wrap {
  display: none;
  width: 100%;
}

.chart-wrap.visible { display: block; }

.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-empty {
  display: none;
  font-size: 13.5px;
  color: var(--muted);
  padding: 30px 0;
  text-align: center;
}

.chart-empty.visible { display: block; }

.chart-point-label {
  font-size: 10.5px;
  fill: var(--muted);
  font-family: var(--font-body);
}

.chart-value-label {
  font-size: 11px;
  fill: var(--text);
  font-weight: 600;
  font-family: var(--font-body);
}

/* ---------- Lists grid (top pages / sources / devices / browsers) ---------- */
.analytics-lists-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

@media (max-width: 900px) {
  .analytics-lists-grid { grid-template-columns: 1fr; }
}

.bar-list {
  display: none;
  flex-direction: column;
  gap: 14px;
  list-style: none;
}

.bar-list.visible { display: flex; }

.bar-list-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bar-list-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
}

.bar-list-name {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.bar-list-count {
  flex-shrink: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar-list-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.bar-list-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}

/* Plain variant (landing pages) — no bar track, just name + count */
.bar-list-plain .bar-list-top { font-size: 14px; }
.bar-list-plain .bar-list-row { gap: 0; }

/* ---------- Engagement rows ---------- */
.engagement-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.engagement-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.engagement-row:last-child { border-bottom: none; }

.engagement-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.engagement-value {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

/* ---------- Empty state (no analytics data at all) ---------- */
.analytics-empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.analytics-empty-state.visible { display: flex; }

.analytics-empty-state svg { color: var(--border); }

.analytics-empty-state p {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.analytics-empty-sub {
  font-size: 13.5px !important;
  font-weight: 500 !important;
  color: var(--muted) !important;
  max-width: 360px;
}

#analytics-main {
  display: none;
}

#analytics-main.visible {
  display: block;
}

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  .analytics-topline-actions {
    width: 100%;
    justify-content: space-between;
  }
  .range-tabs {
    flex: 1;
    justify-content: space-between;
  }
  .range-tab { padding: 8px 10px; flex: 1; text-align: center; }
}

@media (max-width: 480px) {
  .live-recent-item { flex-direction: column; align-items: flex-start; gap: 4px; }
}
