/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:       #080c14;
  --bg-layer:      #0d1424;
  --bg-glass:      rgba(255,255,255,0.04);
  --bg-glass-h:    rgba(255,255,255,0.07);
  --border:        rgba(255,255,255,0.08);
  --border-h:      rgba(255,255,255,0.15);

  --text-primary:  #e8edf5;
  --text-secondary:#8892a4;
  --text-muted:    #4a5568;

  --accent-blue:   #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-cyan:   #06b6d4;
  --accent-green:  #10b981;
  --accent-red:    #ef4444;
  --accent-amber:  #f59e0b;

  --gradient-blue:   linear-gradient(135deg, #3b82f6, #2563eb);
  --gradient-purple: linear-gradient(135deg, #8b5cf6, #6d28d9);
  --gradient-cyan:   linear-gradient(135deg, #06b6d4, #0891b2);
  --gradient-green:  linear-gradient(135deg, #10b981, #059669);

  --sidebar-w: 220px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --font: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.04) inset;
  --shadow-glow: 0 0 40px rgba(59,130,246,0.15);
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Animated mesh background */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(59,130,246,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(139,92,246,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 40% 40% at 50% 50%, rgba(6,182,212,0.04) 0%, transparent 70%);
  pointer-events: none;
}

/* ── Utilities ───────────────────────────────────────────── */
.hidden { display: none !important; }
.mono   { font-family: var(--font-mono); }

.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

.glass:hover {
  border-color: var(--border-h);
}

/* ── Loading Overlay ─────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease;
}

.loading-overlay.fade-out {
  opacity: 0; pointer-events: none;
}

.loading-pulse {
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}

/* ── Logo Ring ───────────────────────────────────────────── */
.logo-ring {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(59,130,246,0.2), rgba(139,92,246,0.2));
  border: 1px solid rgba(59,130,246,0.3);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-blue);
  position: relative;
}

.logo-ring::after {
  content: '';
  position: absolute; inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(59,130,246,0.15);
}

.logo-ring.small { width: 34px; height: 34px; }
.logo-ring.large { width: 72px; height: 72px; }

/* ── Auth Screen ─────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-screen.visible { display: flex !important; }

.auth-card {
  width: 100%; max-width: 400px;
  border-radius: var(--radius-xl);
  padding: 40px;
  animation: slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
  font-weight: 600; font-size: 15px;
  color: var(--text-secondary);
}

.auth-title {
  font-size: 26px; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.auth-sub {
  font-size: 14px; color: var(--text-secondary);
  margin-bottom: 32px; line-height: 1.6;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.input-group { display: flex; flex-direction: column; gap: 6px; }

.input-group label {
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
}

.input-group input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font); font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.input-group input::placeholder { color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--gradient-blue);
  color: #fff;
  box-shadow: 0 4px 16px rgba(59,130,246,0.35);
}
.btn-primary:hover {
  box-shadow: 0 6px 24px rgba(59,130,246,0.5);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-ghost:hover { border-color: var(--border-h); color: var(--text-primary); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-message {
  font-size: 13px; text-align: center; padding: 10px 14px;
  border-radius: var(--radius-sm);
}
.auth-message.success {
  background: rgba(16,185,129,0.1);
  border: 1px solid rgba(16,185,129,0.2);
  color: var(--accent-green);
}
.auth-message.error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  color: var(--accent-red);
}

.auth-footer {
  margin-top: 24px; text-align: center;
  font-size: 12px; color: var(--text-muted);
}

/* ── Passkey button & divider ────────────────────────────── */
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 0;
  color: var(--text-muted); font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1; height: 1px;
  background: var(--border);
}

.btn-passkey {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  gap: 10px;
  transition: all 0.2s;
}
.btn-passkey:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--border-h);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.btn-passkey:disabled {
  opacity: 0.5; cursor: not-allowed; transform: none;
}

/* ── Dashboard Layout ────────────────────────────────────── */
#dashboard {
  display: flex; min-height: 100vh;
}
#dashboard.visible { display: flex !important; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding: 20px 12px;
  border-radius: 0;
  border-right: 1px solid var(--border);
  border-top: none; border-bottom: none; border-left: none;
  position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-title {
  font-weight: 700; font-size: 15px;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}

.nav-item:hover {
  background: var(--bg-glass-h);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(59,130,246,0.12);
  color: var(--accent-blue);
  border: 1px solid rgba(59,130,246,0.2);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex; align-items: center; gap: 8px;
}

.vm-info { flex: 1; overflow: hidden; }
.vm-ip { font-size: 12px; color: var(--text-muted); display: block; }
.vm-updated { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.icon-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover {
  border-color: var(--border-h);
  color: var(--text-primary);
  background: var(--bg-glass-h);
}

.icon-btn.spinning #refresh-icon {
  animation: spin 0.7s linear infinite;
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1100px;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 32px;
}

.page-title {
  font-size: 24px; font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.page-sub {
  font-size: 13px; color: var(--text-secondary);
}

/* Status badge */
.status-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
}

.status-badge.online {
  background: rgba(16,185,129,0.1);
  border-color: rgba(16,185,129,0.25);
  color: var(--accent-green);
}
.status-badge.offline {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.25);
  color: var(--accent-red);
}
.status-badge.loading {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.25);
  color: var(--accent-amber);
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
.status-badge.online .status-dot { animation: blink 2s ease-in-out infinite; }

@keyframes blink {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

/* ── Sections ────────────────────────────────────────────── */
.section { margin-bottom: 36px; }
.section-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.section-title {
  font-size: 16px; font-weight: 600;
  color: var(--text-primary);
}
.section-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ── Stats Grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.stat-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; align-items: flex-start; gap: 14px;
  position: relative; overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

/* Subtle gradient top line */
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
}

.stat-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.cpu-icon  { background: rgba(59,130,246,0.15);  color: var(--accent-blue); }
.ram-icon  { background: rgba(139,92,246,0.15);  color: var(--accent-purple); }
.disk-icon { background: rgba(6,182,212,0.15);   color: var(--accent-cyan); }
.up-icon   { background: rgba(16,185,129,0.15);  color: var(--accent-green); }

.stat-body { flex: 1; }
.stat-label {
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 26px; font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-sub {
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
}

/* Ring gauge (SVG donut) */
.stat-ring-wrap {
  width: 48px; height: 48px; flex-shrink: 0;
}
.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg {
  fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 3;
}
.ring-fill {
  fill: none; stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dasharray 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.cpu-ring  { stroke: var(--accent-blue); }
.ram-ring  { stroke: var(--accent-purple); }
.disk-ring { stroke: var(--accent-cyan); }

/* ── Services Grid ───────────────────────────────────────── */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.service-card {
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
  transition: all 0.2s;
}

.service-card:hover {
  background: var(--bg-glass-h);
  transform: translateX(2px);
}

.service-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
}
.service-dot.active   { background: var(--accent-green); box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.service-dot.inactive { background: var(--accent-red);   box-shadow: 0 0 8px rgba(239,68,68,0.4); }
.service-dot.unknown  { background: var(--text-muted); }

.service-info { flex: 1; overflow: hidden; }
.service-name {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.service-status {
  font-size: 12px; margin-top: 2px;
  font-family: var(--font-mono);
}
.service-status.active   { color: var(--accent-green); }
.service-status.inactive { color: var(--accent-red); }
.service-status.unknown  { color: var(--text-muted); }

/* Skeleton */
.skeleton-card {
  border-radius: var(--radius-md);
  height: 60px;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.7; }
}

/* ── Indexer Card ────────────────────────────────────────── */
.indexer-card {
  border-radius: var(--radius-lg);
  padding: 24px;
}

.indexer-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.indexer-row:last-of-type { border-bottom: none; }

.indexer-label { font-size: 13px; color: var(--text-secondary); }

.indexer-logs-wrap { margin-top: 16px; }

.log-box {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.7;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-box::-webkit-scrollbar { width: 4px; }
.log-box::-webkit-scrollbar-track { background: transparent; }
.log-box::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 2px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    width: 100%; min-height: auto; height: 60px;
    flex-direction: row; align-items: center;
    padding: 0 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
  }
  .sidebar-nav, .vm-info, .sidebar-header { display: none; }
  .sidebar-footer {
    border-top: none; padding-top: 0;
    margin-left: auto;
  }
  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
