:root {
  --bg: #121922;
  --bg-soft: #19222d;
  --panel: #1b2430;
  --panel-border: rgba(255, 255, 255, 0.06);
  --text: #e8eef6;
  --muted: #9aa7b8;
  --accent: #2d8bff;
  --accent-2: #1b5fd1;
  --good: #4cc27f;
  --bad: #ff6b6b;
  --gold: #f2b949;
  --shadow: 0 30px 80px rgba(6, 12, 20, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Avenir", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 20%, #22314a 0%, var(--bg) 40%, #0f151d 100%);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 80% 10%, rgba(45, 139, 255, 0.2), transparent 40%),
              radial-gradient(circle at 20% 80%, rgba(76, 194, 127, 0.15), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

.page {
  max-width: 1500px;
  margin: 0 auto;
  padding: 26px 20px 40px;
  position: relative;
  z-index: 1;
}

.topbar {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.meta-logo {
  width: 40px;
  height: 22px;
  position: relative;
}

.meta-logo .loop {
  position: absolute;
  width: 20px;
  height: 18px;
  border: 3px solid #2d8bff;
  border-radius: 50%;
  top: 2px;
}

.meta-logo .loop:first-child { left: 0; }
.meta-logo .loop:last-child { right: 0; }

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.select .caret {
  color: var(--muted);
  font-size: 12px;
}

.date-range {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.date-range input {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
}

.apply-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.error-banner {
  margin-top: 18px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.4);
  color: #ffd2d2;
  display: flex;
  gap: 10px;
  align-items: center;
}

.error-banner[hidden] {
  display: none;
}

.detail-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.gauge {
  grid-column: span 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 220px;
}

.gauge-wrap {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}

.gauge-value {
  position: absolute;
  top: 58%;
  transform: translateY(-50%);
  font-size: 26px;
  font-weight: 700;
}

.gauge-sub {
  position: absolute;
  top: 72%;
  font-size: 12px;
  color: var(--good);
}

.engagement {
  grid-column: span 3;
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 220px;
}

.big-value {
  font-size: 26px;
  font-weight: 700;
}

.delta {
  font-size: 12px;
}

.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.bar {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  height: 10px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #65d498, #3fbf73);
  width: 0%;
  transition: width 0.6s ease;
}

.mini-note {
  font-size: 12px;
  color: var(--muted);
}

.mini-note strong {
  color: var(--text);
}

.line {
  grid-column: span 6;
  min-height: 220px;
}

.line-legend {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 14px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.dot.green { background: #4cc27f; }
.dot.blue { background: #2d8bff; }

.donut {
  grid-column: span 4;
  min-height: 240px;
}

.legend {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.ads-panel {
  margin-top: 16px;
}

.highlights {
  margin-top: 16px;
}

.highlight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.highlight-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.highlight-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.highlight-thumb {
  height: 140px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(45, 139, 255, 0.25), rgba(242, 185, 73, 0.2));
  display: grid;
  place-items: center;
}

.highlight-link {
  display: block;
  width: 100%;
  height: 100%;
}

.highlight-link[aria-disabled='true'] {
  pointer-events: none;
}

.highlight-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.highlight-title {
  font-size: 14px;
  font-weight: 600;
}

.highlight-metric {
  font-size: 12px;
  color: var(--muted);
}

.highlight-metric strong {
  color: var(--text);
}

.ads-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.ad-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.ad-thumb {
  height: 400px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(45, 139, 255, 0.3), rgba(242, 185, 73, 0.2));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  overflow: hidden;
}

.ad-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ad-thumb.is-empty {
  color: rgba(255, 255, 255, 0.7);
}

.ad-thumb-placeholder {
  font-weight: 700;
  font-size: 20px;
}

.ad-title {
  font-size: 13px;
  font-weight: 600;
}

.ad-link {
  color: inherit;
  text-decoration: none;
  display: grid;
  gap: 8px;
}

.ad-link:hover .ad-title {
  text-decoration: underline;
}

.ad-sub {
  font-size: 12px;
  color: var(--muted);
}

.ad-metrics {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.table {
  margin-top: 16px;
  padding: 0;
}

.table-header,
.table-row {
  display: grid;
  grid-template-columns: 2.2fr 2fr 2fr 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px 16px;
  align-items: center;
  font-size: 13px;
}

.table-header {
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid var(--panel-border);
  font-weight: 600;
}

.th-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.th-btn.right { justify-content: flex-end; }

.th-btn::after {
  content: "↕";
  font-size: 11px;
  color: var(--muted);
}

.th-btn.is-asc::after {
  content: "↑";
  color: var(--text);
}

.th-btn.is-desc::after {
  content: "↓";
  color: var(--text);
}

.table-row {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.table-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.right { text-align: right; }

.table-skeleton { display: none; }
.is-loading .table-skeleton { display: block; }
.is-loading #tableBody { display: none; }
.ads-skeleton { display: none; }
.is-loading .ads-skeleton { display: grid; }
.is-loading #adsGrid { display: none; }

.is-loading [data-skeleton] {
  position: relative;
  color: transparent;
}
.is-loading .ads-skeleton{
  display: flex!important;
  flex-wrap: wrap;
}
.ads-skeleton .ad-card{
  width: 25%;
}

.is-loading [data-skeleton]::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.is-loading canvas { opacity: 0.4; }
.is-loading .bar-fill { width: 25%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (max-width: 1200px) {
  .detail-grid { grid-template-columns: repeat(6, 1fr); }
  .gauge, .engagement { grid-column: span 3; }
  .line { grid-column: span 6; }
  .donut { grid-column: span 6; }
  .highlight-grid { grid-template-columns: 1fr; }
  .ads-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .controls { width: 100%; justify-content: space-between; }
  .detail-grid { grid-template-columns: 1fr; }
  .gauge, .engagement, .line, .donut { grid-column: span 1; }
  .highlight-grid { grid-template-columns: 1fr; }
  .ads-grid { grid-template-columns: 1fr; }
  .table-header, .table-row { grid-template-columns: 1fr 1fr; }
}