:root {
  --bg-0: #05060f;
  --bg-1: #0a0d1f;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.14);
  --text: #eef2ff;
  --muted: rgba(238, 242, 255, 0.62);
  --cyan: #22d3ee;
  --violet: #a78bfa;
  --pink: #f472b6;
  --green: #34d399;
  --red: #fb7185;
  --amber: #fbbf24;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius: 22px;
  --font: 'Vazirmatn', 'Outfit', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-0);
  overflow-x: hidden;
}

body {
  line-height: 1.5;
}

/* ── Animated background ── */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(34, 211, 238, 0.12), transparent 55%),
    radial-gradient(ellipse 70% 50% at 80% 20%, rgba(167, 139, 250, 0.14), transparent 50%),
    radial-gradient(ellipse 60% 40% at 50% 90%, rgba(244, 114, 182, 0.1), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: float 18s ease-in-out infinite;
}

.orb-1 {
  width: 420px; height: 420px;
  background: rgba(34, 211, 238, 0.25);
  top: -80px; left: -60px;
}

.orb-2 {
  width: 500px; height: 500px;
  background: rgba(167, 139, 250, 0.22);
  top: 30%; right: -120px;
  animation-delay: -6s;
}

.orb-3 {
  width: 380px; height: 380px;
  background: rgba(244, 114, 182, 0.18);
  bottom: -100px; left: 35%;
  animation-delay: -12s;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black, transparent);
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 25px) scale(0.97); }
}

/* ── Layout ── */
.app {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Hero ── */
.hero {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 28px;
  margin-bottom: 22px;
  flex-wrap: wrap;
  text-align: center;
}

.hero-left {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
}

.logo-ring {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(34,211,238,0.2), rgba(167,139,250,0.2));
  border: 1px solid rgba(255,255,255,0.18);
}

.logo-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(34, 211, 238, 0.5);
  animation: pulse 2.4s ease-out infinite;
  pointer-events: none;
}

.logo-icon {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--cyan);
  box-shadow: 0 0 16px rgba(34,211,238,0.65);
  flex-shrink: 0;
}

.logo-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--cyan);
}

@keyframes pulse {
  0% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(1.35); opacity: 0; }
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 2px;
}

.hero h1 {
  font-family: 'Outfit', var(--font);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 800;
  background: linear-gradient(90deg, #fff, #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }

.hero-right {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
}

.glass-pill {
  padding: 11px 20px;
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  font-size: 0.85rem;
  color: var(--muted);
}

#updatedAt {
  color: rgba(238,242,255,0.82);
  font-weight: 500;
}

.glass-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.glass-btn:hover {
  background: rgba(255,255,255,0.14);
  transform: translateY(-1px);
  box-shadow: 0 8px 30px rgba(34,211,238,0.15);
}

.glass-btn.primary {
  background: linear-gradient(135deg, rgba(34,211,238,0.25), rgba(167,139,250,0.25));
  border-color: rgba(34,211,238,0.35);
}

.glass-btn.loading .btn-icon {
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  transition: transform 0.25s;
}

.stat-card:hover { transform: translateY(-3px); }

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-value {
  font-family: 'Outfit', var(--font);
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-card.online .stat-value { color: var(--green); }
.stat-card.offline .stat-value { color: var(--red); }
.stat-card.ping .stat-value { color: var(--cyan); }
.stat-card.uptime .stat-value { color: var(--violet); }

.stat-card-uptime .stat-label {
  white-space: nowrap;
}

/* ── Chart section ── */
.chart-section {
  margin-bottom: 28px;
}

.panel {
  padding: 22px 24px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.panel-hint {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.panel-head > div:first-child {
  min-width: 0;
}

.panel-badge {
  font-size: 0.75rem;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
}

.timeline-wrap {
  flex: 1;
  position: relative;
  min-height: 360px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.22);
  color: rgba(238,242,255,0.88);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s, border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.legend-chip:hover {
  transform: translateY(-1px);
  border-color: var(--chip-color, rgba(255,255,255,0.3));
}

.legend-chip:not(.active) {
  opacity: 0.72;
  border-style: dashed;
  background: rgba(0,0,0,0.12);
}

.legend-chip.active {
  border-color: color-mix(in srgb, var(--chip-color, #22d3ee) 55%, transparent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--chip-color, #22d3ee) 25%, transparent);
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 2.5px solid var(--chip-color, #fff);
}

.legend-line-avg {
  border-top-style: dashed;
}

.flag-img {
  display: block;
  border-radius: 5px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0,0,0,0.28);
  flex-shrink: 0;
}

.flag-fallback {
  font-size: 1.4rem;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

/* ── Servers ── */
.servers-section .section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.servers-section h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.servers-section p { color: var(--muted); font-size: 0.9rem; }

.servers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.server-card {
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s, border-color 0.25s;
}

.server-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0; left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  opacity: 0.7;
}

.server-card.offline::before {
  background: linear-gradient(90deg, var(--red), var(--amber));
}

.server-card.offline:hover {
  transform: none;
  border-color: rgba(251, 113, 133, 0.25);
}

.server-card-body {
  position: relative;
  z-index: 0;
}

.server-offline-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: inherit;
  background: rgba(8, 12, 24, 0.62);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  pointer-events: none;
}

.server-offline-overlay span {
  color: #f8fafc;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.7;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  max-width: 220px;
}

.server-card.paused { opacity: 0.55; }

.server-card:hover {
  transform: translateY(-4px);
  border-color: rgba(34,211,238,0.3);
}

.server-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.server-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.server-name {
  font-family: 'Outfit', var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.server-flag,
.server-identity .flag-img,
.server-identity .flag-fallback {
  flex-shrink: 0;
}

.server-identity .flag-img {
  width: 28px;
  height: 20px;
  display: block;
}

.server-identity .flag-fallback {
  font-size: 1.25rem;
  line-height: 1;
}

.status-badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid;
}

.status-badge.ok {
  color: var(--green);
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
}

.status-badge.err {
  color: var(--red);
  background: rgba(251, 113, 133, 0.12);
  border-color: rgba(251, 113, 133, 0.35);
}

.status-badge.pause {
  color: var(--amber);
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.35);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  padding: 12px;
  border-radius: 14px;
  background: rgba(0,0,0,0.22);
  border: 1px solid rgba(255,255,255,0.06);
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric-value {
  font-family: 'Outfit', var(--font);
  font-size: 1.15rem;
  font-weight: 700;
}

.metric-value.good { color: var(--green); }
.metric-value.warn { color: var(--amber); }
.metric-value.bad { color: var(--red); }

.spark-wrap {
  height: 56px;
  margin-top: 4px;
}

.spark-wrap canvas { width: 100% !important; height: 56px !important; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 0.88rem;
  z-index: 100;
  transition: opacity 0.3s;
}

.toast.error { border-color: rgba(251,113,133,0.5); color: var(--red); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .stat-card-uptime { grid-column: span 1; }
}

@media (max-width: 768px) {
  .app { padding: 16px 14px 48px; }

  .hero {
    padding: 16px;
    gap: 14px;
  }

  .hero-left {
    width: 100%;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    text-align: center;
  }

  .hero-left > div:last-child {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .hero h1 { font-size: 1.45rem; }
  .subtitle { font-size: 0.85rem; }

  .hero-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  #updatedAt {
    width: 100%;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  .hero-right .glass-btn {
    width: 100%;
    justify-content: center;
  }

  .glass-pill {
    font-size: 0.85rem;
    padding: 11px 20px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px 16px;
  }

  .stat-card-uptime {
    grid-column: 1 / -1;
  }

  .stat-value { font-size: 1.45rem; }

  .panel {
    padding: 16px;
    min-height: 300px;
  }

  .timeline-wrap { min-height: 260px; }

  .chart-legend { gap: 6px; }

  .legend-chip {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .servers-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .server-card { padding: 16px; }

  .metrics {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .metric { padding: 10px 6px; text-align: center; }

  .metric-value { font-size: 1rem; }

  .server-top {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
  }

  .server-identity {
    justify-content: center;
  }
}

@media (max-width: 400px) {
  .metrics { grid-template-columns: 1fr; }

  .hero-left { gap: 12px; }

  .logo-ring {
    width: 52px;
    height: 52px;
  }

  .logo-pulse {
    width: 52px;
    height: 52px;
  }
}
