#analytics-index {
  display: none;
}

#analytics-workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
}

/* ---- coming soon (Google/TikTok — pipeline only pulls Meta today) ---- */
/* Deliberately its own class, NOT the shared .empty-template — that class
   name is a routing anchor other page-mount scripts (incl. this file's own
   MutationObserver) query for; reusing it on an element nested inside an
   already-mounted page causes the mounter to seize and corrupt it. */

.analytics-empty-panel {
  display: grid;
  min-height: 420px;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(circle at 20% 18%, rgba(214, 0, 87, .1), transparent 28%), linear-gradient(135deg, var(--surface), var(--surface) 48%, var(--surface));
}

.analytics-empty-panel-inner {
  display: grid;
  justify-items: center;
  max-width: 560px;
  padding: 48px 28px;
  text-align: center;
}

.analytics-empty-panel-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.analytics-empty-panel h3 {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 26px;
  font-weight: 780;
  line-height: 1.1;
}

.analytics-empty-panel p {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.6;
}

html[data-theme="dark"] .analytics-empty-panel {
  background: radial-gradient(circle at 20% 18%, rgba(214, 32, 41, .18), transparent 30%), linear-gradient(135deg, var(--surface), var(--accent-softer) 48%, var(--surface));
}

/* ---- filter shell ---- */

.analytics-filter-shell {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ---- platform quick filters ---- */

.analytics-platform-buttons {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.analytics-platform-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border: 1.5px solid var(--platform-color, var(--border));
  border-radius: var(--radius);
  background: transparent;
  color: var(--platform-color, var(--text-soft));
  font: 700 12px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .16s ease, color .16s ease;
}

.analytics-platform-button:hover {
  background: color-mix(in srgb, var(--platform-color, var(--text-soft)) 12%, transparent);
}

.analytics-platform-button.is-active {
  background: var(--platform-color, var(--accent));
  color: #FFFFFF;
}

.analytics-platform-button--facebook { --platform-color: #4267B2; }
.analytics-platform-button--google { --platform-color: #34A853; }
.analytics-platform-button--tiktok { --platform-color: #FE2C55; }

.analytics-date-filter {
  display: grid;
  flex: 0 1 260px;
  gap: 7px;
  min-width: 0;
}

.analytics-search-field {
  display: grid;
  flex: 1 1 140px;
  gap: 7px;
  min-width: 120px;
}

.analytics-metric-field {
  display: grid;
  flex: 0 1 150px;
  gap: 7px;
  min-width: 0;
}

.analytics-filter-shell .select-field--compact {
  flex: 0 1 160px;
  min-width: 120px;
}

.analytics-date-filter > span,
.analytics-search-field > span,
.analytics-metric-field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.analytics-filter-bar {
  display: contents;
}

.analytics-search-field input,
.analytics-metric-field select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 600 13px/1.3 inherit;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.analytics-search-field input {
  padding: 0 11px;
}

.analytics-metric-field select {
  padding: 0 30px 0 11px;
}

.analytics-search-field input:focus,
.analytics-metric-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.analytics-clear-button {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-soft);
  font: 700 12px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
}

.analytics-clear-button:hover {
  border-color: var(--accent);
  background: var(--surface-subtle);
}

/* ---- Tầng 1 / Tầng 2 layout ---- */

.analytics-subheading {
  margin: 0 0 12px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.analytics-tier1-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
}

.analytics-tier2-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.analytics-bars-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.analytics-bars-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.analytics-bars-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analytics-bars-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.analytics-bars-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.analytics-bars-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.analytics-bars-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.analytics-bars-8 { grid-template-columns: repeat(8, minmax(0, 1fr)); }

.bar-fill.analytics-series-a {
  background: var(--accent);
}

.bar-fill.analytics-series-b {
  background: var(--blue);
}

.analytics-legend-row {
  display: flex;
  gap: 16px;
  margin-top: 12px;
}

.legend-dot.analytics-legend-a:before {
  background: var(--accent);
}

.legend-dot.analytics-legend-b:before {
  background: var(--blue);
}

.analytics-empty-note {
  grid-column: 1 / -1;
  margin: 0;
  padding: 40px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---- Tầng 2: ranking list ---- */

.analytics-rank-list {
  display: grid;
  gap: 14px;
}

.analytics-rank-item {
  display: grid;
  gap: 8px;
}

.analytics-rank-item__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.analytics-rank-item__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  font-size: 15px;
}

.analytics-rank-item__label {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.analytics-rank-item__value {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.analytics-rank-item__track {
  height: 8px;
  border-radius: 999px;
  background: #222228;
  overflow: hidden;
}

.analytics-rank-item__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* ---- Tầng 3: detail table ---- */

.analytics-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.analytics-detail-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.analytics-detail-controls select {
  height: 36px;
  padding: 0 28px 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 600 13px/1.3 inherit;
}

.analytics-export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
}

.analytics-export-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.analytics-detail-table-wrap {
  max-height: 460px;
  overflow: auto;
  border-top: 1px solid var(--border-soft);
}

.analytics-detail-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.analytics-detail-table th,
.analytics-detail-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  text-align: left;
  white-space: nowrap;
}

.analytics-detail-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.analytics-detail-table td {
  color: var(--text-soft);
  font-size: 13px;
}

.analytics-detail-label {
  color: var(--text);
  font-weight: 650;
}

.analytics-detail-table tbody tr:hover td {
  background: var(--accent-softer);
}

.analytics-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.analytics-sort:hover,
.analytics-sort:focus-visible,
.analytics-sort.is-active {
  color: var(--text);
}

.analytics-sort:focus-visible {
  border-radius: 4px;
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.analytics-sort__icons {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.analytics-sort__arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  opacity: .6;
}

.analytics-sort__arrow.is-current {
  color: var(--accent);
  opacity: 1;
  font-weight: 700;
}

.analytics-detail-empty td {
  padding: 30px 16px;
  color: var(--muted);
  text-align: center;
  white-space: normal;
}

/* ---- responsive ---- */

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

  .analytics-tier1-grid > div:last-child {
    grid-column: span 2;
  }
}

@media (max-width: 820px) {
  .analytics-filter-shell {
    flex-wrap: wrap;
  }

  .analytics-platform-buttons,
  .analytics-date-filter,
  .analytics-search-field,
  .analytics-metric-field,
  .analytics-clear-button {
    flex: 1 1 220px;
  }

  .analytics-clear-button {
    width: 100%;
  }

  .analytics-tier1-grid,
  .analytics-tier2-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .analytics-tier1-grid > div:last-child {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .analytics-filter-shell {
    padding: 14px;
  }

  .analytics-detail-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
