/* ============================================================
   Analytics Popup
   ============================================================ */
.analytics-modal {
  --av-accent:    #a78bfa;
  --av-accent-bg: rgba(167,139,250,.12);

  background: var(--modal-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  overflow: hidden;
}

/* Header */
.av-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--card-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.av-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.av-eye-icon {
  width: 22px; height: 22px;
  color: var(--av-accent);
  flex-shrink: 0;
}

.av-header-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.av-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* Tabs */
.av-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,.05);
  border-radius: var(--radius-full);
  padding: 3px;
  flex-shrink: 0;
}

.av-tab {
  padding: 5px 13px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.av-tab:hover { color: var(--text); }
.av-tab.active {
  background: var(--av-accent-bg);
  color: var(--av-accent);
}

/* Theme dots */
.av-themes {
  display: flex;
  gap: 5px;
  align-items: center;
}

.av-theme-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.av-theme-dot:hover  { transform: scale(1.2); }
.av-theme-dot.active { border-color: #fff; transform: scale(1.15); }

/* Body */
.av-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
}

.av-loading, .av-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}

.av-error { color: var(--danger); font-size: 0.9rem; }

/* Empty state */
.av-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 50px 30px;
  text-align: center;
}
.av-empty svg {
  width: 52px; height: 52px;
  color: var(--av-accent);
  opacity: .35;
}
.av-empty-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.av-empty-sub {
  font-size: 0.86rem;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.55;
}

/* Shared */
.av-section {
  margin-bottom: 22px;
}
.av-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.av-muted { color: var(--text-muted); font-size: 0.82rem; }
.av-icon  { width: 14px; height: 14px; vertical-align: middle; flex-shrink: 0; }

/* ---- Overview ---- */
.av-overview { display: flex; flex-direction: column; gap: 4px; }

.av-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.av-stat {
  background: var(--av-accent-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: center;
}
.av-stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--av-accent);
  line-height: 1;
  margin-bottom: 4px;
}
.av-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Bar chart */
.av-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
  padding: 4px 0 0;
}
.av-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.av-bar-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.av-bar {
  width: 100%;
  max-width: 32px;
  background: var(--av-accent);
  border-radius: 3px 3px 0 0;
  opacity: .75;
  transition: opacity 0.15s;
  min-height: 2px;
}
.av-bar-col:hover .av-bar { opacity: 1; }
.av-bar-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Two column layout */
.av-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

/* Locations */
.av-loc-list { display: flex; flex-direction: column; gap: 6px; }
.av-loc-row  {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.av-flag { font-size: 1.1rem; flex-shrink: 0; }
.av-loc-name { flex: 1; color: var(--text); font-weight: 500; }
.av-loc-count {
  font-size: 0.78rem;
  color: var(--av-accent);
  font-weight: 700;
  background: var(--av-accent-bg);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}

/* Top content in overview */
.av-content-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--card-border);
}
.av-content-row:last-child { border-bottom: none; }
.av-rank-num   { color: var(--text-subtle); font-size: 0.72rem; width: 14px; text-align: center; flex-shrink: 0; }
.av-content-path { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-content-views { color: var(--av-accent); font-weight: 700; font-size: 0.78rem; flex-shrink: 0; }

/* Visitor chips (recent) */
.av-visitor-chips { display: flex; flex-direction: column; gap: 6px; }
.av-visitor-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
}
.av-visitor-chip .av-flag { font-size: 1.2rem; }
.av-visitor-chip-info { flex: 1; min-width: 0; }
.av-visitor-chip-loc  {
  font-weight: 600;
  color: var(--text);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.av-visitor-chip-meta { font-size: 0.75rem; color: var(--text-muted); }
.av-visitor-chip-pages { color: var(--av-accent); font-weight: 700; font-size: 0.78rem; flex-shrink: 0; }

/* ---- Content tab ---- */
.av-content-list { display: flex; flex-direction: column; gap: 8px; }

.av-content-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
}
.av-content-rank {
  font-size: 1rem;
  font-weight: 800;
  color: var(--av-accent);
  opacity: .5;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.av-content-main { flex: 1; min-width: 0; }
.av-content-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.av-content-url {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}
.av-content-bar {
  height: 3px;
  background: rgba(255,255,255,.06);
  border-radius: 2px;
  overflow: hidden;
}
.av-content-bar-fill {
  height: 100%;
  background: var(--av-accent);
  border-radius: 2px;
  transition: width .5s ease;
}
.av-content-stats {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 0 12px;
  text-align: right;
  flex-shrink: 0;
}
.av-content-stat-val {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.av-content-stat-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 6px;
}
.av-scroll-badge {
  grid-column: 1 / -1;
  text-align: right;
  font-size: 0.7rem;
  color: var(--av-accent);
  background: var(--av-accent-bg);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* ---- Visitors tab ---- */
.av-visitors-list  { display: flex; flex-direction: column; gap: 6px; }
.av-pagination { padding: 14px 0 0; font-size: 0.82rem; }

.av-visitor-row {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255,255,255,.03);
}

.av-visitor-main {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}
.av-visitor-flag { font-size: 1.4rem; flex-shrink: 0; }
.av-visitor-info { flex: 1; min-width: 0; }
.av-visitor-top  {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.av-visitor-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px dashed var(--text-subtle);
}
.av-visitor-label:hover { color: var(--av-accent); border-color: var(--av-accent); }

.av-label-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--av-accent);
  background: var(--av-accent-bg);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}
.av-label-input {
  background: var(--input-bg);
  border: 1px solid var(--av-accent);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  min-width: 0;
  max-width: 200px;
}
.av-visitor-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.av-visitor-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.av-visitor-pages {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--av-accent);
}
.av-visitor-pages span { font-weight: 400; font-size: 0.75rem; color: var(--text-muted); }
.av-visitor-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.av-expand-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.av-expand-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.av-expand-btn svg   { width: 18px; height: 18px; transition: transform 0.2s; }

.av-visitor-detail {
  border-top: 1px solid var(--card-border);
  padding: 10px 12px;
  background: rgba(0,0,0,.15);
}
.av-detail-loading { display: flex; justify-content: center; padding: 16px; }

.av-detail-views { display: flex; flex-direction: column; gap: 4px; }
.av-detail-view  {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  padding: 4px 0;
}
.av-detail-time  { color: var(--text-muted); flex-shrink: 0; min-width: 55px; }
.av-detail-path  { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-detail-dur   { color: var(--av-accent); font-weight: 600; flex-shrink: 0; }
.av-detail-scroll { font-size: 0.7rem; color: var(--text-muted); background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }

/* ---- Activity tab ---- */
.av-activity-list { display: flex; flex-direction: column; }
.av-activity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.av-activity-item:last-child { border-bottom: none; }
.av-activity-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.av-activity-left .av-icon { color: var(--text-muted); }
.av-activity-page {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.av-activity-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.av-activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .analytics-modal {
    max-height: 95vh;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    position: fixed !important;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
  }
  #analytics-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .av-stats-row { grid-template-columns: repeat(2, 1fr); }
  .av-two-col   { grid-template-columns: 1fr; }
  .av-tabs { gap: 1px; }
  .av-tab  { padding: 5px 9px; font-size: 0.72rem; }
  .av-themes { display: none; }
  .av-header { gap: 6px; }
}

/* ---- New utility styles ---- */
.av-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--av-accent) 15%, transparent);
  color: var(--av-accent);
  border: 1px solid color-mix(in srgb, var(--av-accent) 35%, transparent);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.av-export-btn:hover {
  background: color-mix(in srgb, var(--av-accent) 25%, transparent);
}

.av-detail-extra {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 6px 14px 4px;
  border-bottom: 1px solid var(--card-border);
  line-height: 1.6;
}

.av-detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--card-border);
  gap: 10px;
}

.av-clear-btn {
  background: none;
  border: 1px solid rgba(239,68,68,.35);
  color: rgba(239,68,68,.8);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.av-clear-btn:hover {
  background: rgba(239,68,68,.12);
  color: rgb(239,68,68);
}

/* ============================================================
