:root {
  --analytics-bg-0: #05090f;
  --analytics-bg-1: #0a121d;
  --analytics-bg-2: #102031;
  --analytics-card: rgba(8, 20, 33, 0.82);
  --analytics-card-border: rgba(117, 173, 227, 0.2);
  --analytics-text: #e8f2ff;
  --analytics-text-muted: #94a9c1;
  --analytics-accent: #18e5a2;
  --analytics-accent-soft: rgba(24, 229, 162, 0.16);
  --analytics-highlight: #56b7ff;
  --analytics-danger: #ff6e71;
  --analytics-warning: #ffbb5a;
  --analytics-shadow: 0 22px 70px rgba(2, 8, 14, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  color: var(--analytics-text);
  font-family: "IBM Plex Sans", sans-serif;
  background:
    radial-gradient(circle at 14% 12%, rgba(24, 229, 162, 0.14), transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(86, 183, 255, 0.2), transparent 30%),
    radial-gradient(circle at 80% 80%, rgba(255, 110, 113, 0.12), transparent 36%),
    linear-gradient(160deg, var(--analytics-bg-0) 0%, var(--analytics-bg-1) 42%, #05080e 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(174, 205, 237, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(174, 205, 237, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at center, black 38%, transparent 96%);
  z-index: -1;
}

.analytics-page {
  width: min(1440px, 94vw);
  margin: 0 auto;
  padding: 2.2rem 0 3.2rem;
}

.analytics-hero {
  position: relative;
  padding: 2rem 0.4rem 1.6rem;
  animation: rise-in 0.55s ease both;
}

.analytics-eyebrow {
  margin: 0;
  color: var(--analytics-accent);
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
}

.analytics-hero h1 {
  margin: 0.4rem 0 0.6rem;
  font-family: "Sora", sans-serif;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -0.03em;
  max-width: 16ch;
  text-wrap: balance;
}

.analytics-subtitle {
  margin: 0;
  max-width: 62ch;
  color: var(--analytics-text-muted);
  line-height: 1.55;
}

.card-surface,
.auth-card {
  border: 1px solid var(--analytics-card-border);
  background: linear-gradient(145deg, rgba(10, 23, 37, 0.9), var(--analytics-card));
  border-radius: 18px;
  box-shadow: var(--analytics-shadow);
  backdrop-filter: blur(6px);
}

.auth-state {
  margin-top: 1.25rem;
}

.auth-card {
  padding: 1.8rem;
}

.auth-card h2 {
  margin: 0 0 0.5rem;
  font-family: "Sora", sans-serif;
}

.auth-card p {
  margin: 0;
  color: var(--analytics-text-muted);
}

.hidden {
  display: none !important;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1rem 1rem 1.15rem;
  margin-top: 0.2rem;
  margin-bottom: 1rem;
  animation: rise-in 0.55s ease both;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.toolbar-label {
  font-weight: 700;
  color: var(--analytics-text-muted);
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.period-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.period-btn,
.action-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.period-btn {
  padding: 0.58rem 1rem;
  background: rgba(161, 197, 235, 0.08);
  color: var(--analytics-text);
  border-color: rgba(150, 184, 220, 0.2);
}

.period-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(24, 229, 162, 0.6);
}

.period-btn.is-active {
  background: linear-gradient(140deg, rgba(24, 229, 162, 0.2), rgba(86, 183, 255, 0.25));
  border-color: rgba(24, 229, 162, 0.7);
  color: #f8ffff;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.action-btn {
  padding: 0.65rem 1.05rem;
  background: linear-gradient(140deg, rgba(24, 229, 162, 0.25), rgba(86, 183, 255, 0.25));
  color: #ffffff;
  border-color: rgba(86, 183, 255, 0.55);
}

.action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(24, 229, 162, 0.75);
}

.updated-at {
  margin: 0;
  font-size: 0.8rem;
  color: var(--analytics-text-muted);
}

.error-banner {
  margin-bottom: 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 110, 113, 0.5);
  background: rgba(255, 110, 113, 0.11);
  color: #ffd7d8;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.kpi-card {
  padding: 1rem;
  min-height: 124px;
  position: relative;
  overflow: hidden;
  animation: rise-in 0.55s ease both;
}

.kpi-card::after {
  content: "";
  position: absolute;
  inset: auto -20% -62% auto;
  width: 130px;
  height: 130px;
  background: radial-gradient(circle, rgba(86, 183, 255, 0.18), transparent 62%);
  pointer-events: none;
}

.kpi-card h3 {
  margin: 0;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--analytics-text-muted);
}

.kpi-value {
  margin: 0.6rem 0 0.24rem;
  font-family: "Sora", sans-serif;
  font-size: clamp(1.5rem, 3vw, 2.08rem);
  letter-spacing: -0.02em;
}

.kpi-meta {
  margin: 0;
  font-size: 0.82rem;
  color: #b8cadf;
}

.kpi-delta {
  display: inline-flex;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}

.kpi-delta.up {
  color: #b5ffde;
  background: rgba(24, 229, 162, 0.18);
}

.kpi-delta.down {
  color: #ffd0d1;
  background: rgba(255, 110, 113, 0.18);
}

.kpi-delta.flat {
  color: #dae8f8;
  background: rgba(170, 196, 228, 0.16);
}

.chart-grid {
  display: grid;
  gap: 0.9rem;
  margin-bottom: 0.95rem;
}

.chart-grid-main,
.chart-grid-secondary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-card {
  padding: 1rem;
  min-height: 320px;
  animation: rise-in 0.55s ease both;
}

.chart-card canvas {
  width: 100% !important;
  height: 255px !important;
}

.chart-head {
  margin-bottom: 0.7rem;
}

.chart-head h3 {
  margin: 0;
  font-size: 1.02rem;
  font-family: "Sora", sans-serif;
}

.chart-head p {
  margin: 0.28rem 0 0;
  color: var(--analytics-text-muted);
  font-size: 0.85rem;
}

.insight-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.insight-card {
  padding: 1rem;
  min-height: 240px;
  animation: rise-in 0.55s ease both;
}

.insight-card h3 {
  margin: 0 0 0.8rem;
  font-family: "Sora", sans-serif;
  font-size: 1rem;
}

.list-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.list-item {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.52rem 0.6rem;
  border-radius: 10px;
  background: rgba(116, 160, 206, 0.1);
  border: 1px solid rgba(130, 172, 216, 0.16);
}

.list-rank {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(24, 229, 162, 0.15);
  color: #beffe3;
}

.list-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-subtitle {
  color: var(--analytics-text-muted);
  font-size: 0.77rem;
  margin-top: 0.16rem;
}

.list-value {
  font-weight: 700;
  color: #dcf6ff;
  font-size: 0.84rem;
}

.empty-state {
  margin: 0;
  font-size: 0.86rem;
  color: var(--analytics-text-muted);
  border: 1px dashed rgba(141, 178, 220, 0.35);
  border-radius: 10px;
  padding: 0.85rem;
  text-align: center;
}

.server-section {
  padding: 1rem;
  animation: rise-in 0.55s ease both;
}

.server-section-head {
  display: flex;
  justify-content: space-between;
  gap: 0.9rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.server-section-head h3 {
  margin: 0;
  font-family: "Sora", sans-serif;
  font-size: 1.06rem;
}

.server-section-head p {
  margin: 0.26rem 0 0;
  color: var(--analytics-text-muted);
  font-size: 0.85rem;
}

.server-actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.server-actions input {
  min-width: 245px;
  border-radius: 12px;
  border: 1px solid rgba(121, 162, 206, 0.34);
  background: rgba(8, 21, 35, 0.82);
  color: var(--analytics-text);
  padding: 0.58rem 0.72rem;
  font-family: "IBM Plex Sans", sans-serif;
}

.server-actions input:focus {
  outline: none;
  border-color: rgba(24, 229, 162, 0.74);
}

.server-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.88rem;
}

.server-stat {
  border-radius: 12px;
  border: 1px solid rgba(128, 171, 218, 0.22);
  background: rgba(10, 23, 37, 0.75);
  padding: 0.62rem 0.75rem;
}

.server-stat-label {
  margin: 0;
  font-size: 0.75rem;
  color: var(--analytics-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.server-stat-value {
  margin: 0.3rem 0 0;
  font-size: 1.18rem;
  font-family: "Sora", sans-serif;
}

.server-table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(128, 171, 218, 0.2);
}

.server-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.server-table th,
.server-table td {
  padding: 0.66rem 0.7rem;
  border-bottom: 1px solid rgba(128, 171, 218, 0.16);
  font-size: 0.84rem;
  text-align: left;
}

.server-table th {
  background: rgba(11, 25, 40, 0.88);
  color: #d5e9ff;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.server-table tr:hover td {
  background: rgba(35, 77, 121, 0.16);
}

.status-pill {
  display: inline-flex;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.status-pill.active {
  color: #b7ffd9;
  background: rgba(24, 229, 162, 0.16);
}

.status-pill.inactive {
  color: #ffd4d5;
  background: rgba(255, 110, 113, 0.16);
}

.empty-row {
  text-align: center;
  color: var(--analytics-text-muted);
  background: rgba(10, 25, 40, 0.74);
  font-style: italic;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.retention-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.retention-card {
  border: 1px solid rgba(128, 171, 218, 0.24);
  background: rgba(10, 23, 37, 0.75);
  border-radius: 12px;
  padding: 0.7rem;
}

.retention-card h4 {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--analytics-text-muted);
  letter-spacing: 0.04em;
}

.retention-card .value {
  margin: 0.28rem 0 0;
  font-family: "Sora", sans-serif;
  font-size: 1.25rem;
}

.retention-card .meta {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--analytics-text-muted);
}

.heatmap-section {
  padding: 1rem;
  margin-bottom: 1rem;
}

.heatmap-wrap {
  overflow: auto;
}

.heatmap-tutorial {
  margin-bottom: 0.8rem;
  border: 1px solid rgba(128, 171, 218, 0.24);
  border-radius: 12px;
  background: rgba(10, 23, 37, 0.68);
  padding: 0.72rem 0.85rem;
}

.heatmap-tutorial summary {
  cursor: pointer;
  font-weight: 700;
  color: #d8ecff;
  font-size: 0.9rem;
}

.heatmap-tutorial-content {
  margin-top: 0.55rem;
}

.heatmap-tutorial-content p {
  margin: 0.2rem 0;
  color: var(--analytics-text-muted);
  font-size: 0.82rem;
}

.heatmap-tutorial-content ul {
  margin: 0.55rem 0 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.35rem;
}

.heatmap-tutorial-content li {
  color: #dcecff;
  font-size: 0.82rem;
}

.heatmap-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.heatmap-table th,
.heatmap-table td {
  border: 1px solid rgba(128, 171, 218, 0.16);
  text-align: center;
  padding: 0.35rem 0.3rem;
  font-size: 0.74rem;
}

.heatmap-table th {
  background: rgba(11, 25, 40, 0.88);
  color: #d5e9ff;
  position: sticky;
  top: 0;
}

.heatmap-day {
  font-weight: 700;
  background: rgba(11, 25, 40, 0.88);
}

.heat-cell {
  color: #e8f2ff;
  min-width: 34px;
}

@media (max-width: 1180px) {
  .chart-grid-main,
  .chart-grid-secondary,
  .insight-grid {
    grid-template-columns: 1fr;
  }

  .chart-card canvas {
    height: 232px !important;
  }

  .retention-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .analytics-page {
    width: min(96vw, 100%);
  }

  .analytics-hero {
    padding-top: 1.4rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .server-section-head {
    flex-direction: column;
  }

  .server-actions {
    width: 100%;
  }

  .server-actions input {
    min-width: 100%;
  }
}
