/* 访问统计：日期筛选、关键指标、页面访问表、排行与分布、按日明细。 */

.analytics-view,
.analytics-results {
  display: grid;
  min-width: 0;
  gap: var(--space-6);
}

.analytics-view .panel,
.analytics-view .metric-card {
  min-width: 0;
}

/* 页头与表格直接对齐工作区，表格滚动限制在自身容器内。 */
.analytics-pages-panel,
.analytics-grid > .panel,
.analytics-daily-panel {
  padding: 0 0 var(--space-4);
  overflow: visible;
}

.analytics-pages-panel > .panel-head,
.analytics-grid > .panel > .panel-head {
  margin: 0;
  padding: 0 0 var(--space-3);
  border-bottom: 0;
}

/* ---------- 日期筛选 ---------- */

.analytics-filter-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: end;
  gap: 16px 24px;
}

.analytics-filter-panel > .panel-head {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.analytics-presets {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.analytics-presets .ghost-button {
  min-height: 32px;
  border-color: transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
}

.analytics-presets .ghost-button:not(:disabled):hover {
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.analytics-presets .ghost-button[aria-pressed="true"],
.analytics-presets .ghost-button[aria-pressed="true"]:hover {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

.analytics-date-form {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.analytics-date-form label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.analytics-date-form label > span {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

.analytics-date-form input {
  width: 168px;
  font-variant-numeric: tabular-nums;
}

.analytics-status {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.analytics-status:empty {
  display: none;
}

.analytics-status[data-state="error"] {
  color: var(--danger);
}

/* ---------- 范围说明与关键指标 ---------- */

.analytics-range-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: -8px;
  color: var(--muted);
  font-size: 13px;
}

.analytics-range-line strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.analytics-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4) var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--line);
}

.analytics-metrics .metric-card strong {
  font-size: 30px;
}

.analytics-results[aria-busy="true"] .analytics-metrics strong {
  color: var(--muted);
}

.analytics-count {
  flex: 0 0 auto;
  justify-self: start;
  width: fit-content;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- 表格 ---------- */

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-6);
}

.analytics-table-wrap {
  width: 100%;
  max-height: 560px;
  overflow: auto;
  overscroll-behavior: contain;
  min-width: 0;
  max-width: 100%;
}

.analytics-grid .analytics-table-wrap {
  max-height: 440px;
}

.analytics-table-wrap:focus-visible {
  outline-offset: -2px;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.5;
}

.analytics-table th,
.analytics-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.analytics-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg);
}

.analytics-table th:first-child,
.analytics-table td:first-child {
  padding-left: 20px;
}

.analytics-table th:last-child,
.analytics-table td:last-child {
  padding-right: 20px;
}

.analytics-table tbody tr:last-child td {
  border-bottom: 0;
}

.analytics-table tbody tr:hover td {
  background: var(--surface-soft);
}

.analytics-table tbody tr:hover td.analytics-empty {
  background: transparent;
}

.analytics-table td:first-child {
  min-width: 140px;
  overflow-wrap: anywhere;
}

.analytics-pages-table td:first-child {
  width: 70%;
  min-width: 210px;
}

.analytics-table .analytics-number {
  width: 1%;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.analytics-table td.analytics-number {
  color: var(--text);
  font-weight: 500;
}

.analytics-type {
  color: var(--muted);
  white-space: nowrap;
}

.analytics-page-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text);
  font-weight: 500;
}

.analytics-page-path {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.analytics-rank {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 1px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

tr:nth-child(-n + 3) > td > .analytics-page-title .analytics-rank {
  background: var(--accent-soft);
  color: var(--accent);
}

.analytics-table td.analytics-empty {
  padding: 32px 16px;
  color: var(--muted);
  text-align: center;
}

/* ---------- 分页 ---------- */

.analytics-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: var(--space-3) 0 0;
}

.analytics-pagination > div {
  display: flex;
  gap: 8px;
}

.analytics-pagination .ghost-button {
  min-height: var(--control-height-sm);
  padding: 0 12px;
  font-size: 13px;
}

/* ---------- 按日明细（可折叠） ---------- */

.analytics-daily-panel > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  font-size: 16px;
  font-weight: 650;
  padding: var(--space-3) 0;
}

.analytics-daily-panel > summary::-webkit-details-marker {
  display: none;
}

.analytics-daily-panel > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  margin: 0 4px 0 2px;
  border-right: 1.8px solid var(--muted);
  border-bottom: 1.8px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s var(--ease);
}

.analytics-daily-panel[open] > summary::before {
  transform: rotate(45deg);
}

.analytics-daily-panel > summary:hover {
  background: var(--surface-soft);
}

.analytics-daily-panel[open] > summary {
  border-bottom: 1px solid var(--line);
}

.analytics-daily-panel > .panel-copy {
  margin: 0;
  border-bottom: 1px solid var(--line);
  padding: var(--space-3) 0;
}

/* ---------- 统计口径 ---------- */

.analytics-notes {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
  padding: 0 0 var(--space-4);
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.analytics-notes p {
  margin: 0;
}

.analytics-notes p + p {
  margin-top: 6px;
}

/* ---------- 响应式 ---------- */

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

  .analytics-grid .analytics-table td:first-child {
    width: 75%;
  }

  .analytics-grid .analytics-table-wrap {
    max-height: 360px;
  }
}

@media (max-width: 1080px) {
  .analytics-filter-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .analytics-date-form {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .analytics-metrics {
    gap: var(--space-3);
  }

  .analytics-metrics .metric-card > span {
    font-size: 12px;
  }

  .analytics-metrics .metric-card strong {
    font-size: 20px;
  }

  .analytics-metrics .metric-card p {
    display: none;
  }

  .analytics-filter-panel > .panel-head {
    display: flex;
    flex-wrap: nowrap;
  }

  .analytics-presets {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }

  .analytics-presets .ghost-button {
    padding: 0 4px;
  }

  .analytics-date-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analytics-date-form label,
  .analytics-date-form input {
    width: 100%;
    min-width: 0;
  }

  .analytics-date-form button {
    grid-column: 1 / -1;
  }

  .analytics-range-line {
    flex-direction: column;
    gap: 2px;
  }

  .analytics-table th,
  .analytics-table td {
    padding: 9px 12px;
  }

  .analytics-table th:first-child,
  .analytics-table td:first-child {
    padding-left: 16px;
  }

  .analytics-table th:last-child,
  .analytics-table td:last-child {
    padding-right: 16px;
  }

  .analytics-pages-table td:first-child {
    min-width: 150px;
  }

}
