:root {
  --bg: #0a0e1a;
  --bg-elevated: #10152699;
  --card: #131a2c;
  --card-border: #232c45;
  --card-border-hover: #34406a;
  --text: #eef1f8;
  --text-dim: #8b93ac;
  --text-faint: #5c6584;
  --accent: #7c6cf0;
  --accent-hover: #8f81f5;
  --accent-dim: #7c6cf022;
  --online: #34d399;
  --offline: #f87171;
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-dim: #f8717118;
  --radius: 16px;
  --radius-sm: 10px;
  font-family: 'Vazirmatn', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse 900px 500px at 15% -5%, #1a2547 0%, transparent 60%),
              radial-gradient(ellipse 700px 500px at 100% 100%, #16233d 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  direction: rtl;
}

button, input, select {
  font-family: 'Vazirmatn', sans-serif;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  direction: ltr;
  unicode-bidi: plaintext;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 80px;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}
.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 0 0 6px;
}
.page-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.count-pill {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-dim);
}
.back-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: 10px;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  margin-left: 12px;
}
.back-btn:hover { color: var(--text); border-color: var(--card-border-hover); }
.titlebar-row { display: flex; align-items: center; }

/* ---------- Server card ---------- */
.server-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  transition: border-color 0.15s ease;
}
.server-card:hover { border-color: var(--card-border-hover); }

.server-card-head {
  display: flex;
  align-items: center;
  gap: 14px;
}
.server-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(160deg, #1c2440, #131a2c);
  border: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-size: 20px;
  flex-shrink: 0;
}
.server-meta { flex: 1; min-width: 0; }
.server-name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.server-name { font-weight: 700; font-size: 16px; }
.badge {
  background: var(--accent-dim);
  color: var(--accent-hover);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #7c6cf03a;
}
.server-sub {
  color: var(--text-faint);
  font-size: 12.5px;
  margin-top: 3px;
}
.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}
.status-dot.online { background: var(--online); color: var(--online); }
.status-dot.offline { background: var(--offline); color: var(--offline); }
.status-dot.unknown { background: var(--text-faint); color: var(--text-faint); box-shadow: none; }

.quick-stats {
  display: flex;
  gap: 14px;
  margin: 12px 0 4px;
  padding: 10px 12px;
  background: #0d1220;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-dim);
}
.quick-stats span b { color: var(--text); font-family: 'JetBrains Mono', monospace; }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: filter 0.12s ease, transform 0.06s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: white; flex: 1; justify-content: center; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: #1a2138; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: #212a45; }
.btn-danger { background: var(--danger-dim); color: var(--danger); }
.btn-danger:hover { filter: brightness(1.15); }
.btn-sm { padding: 7px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fab {
  position: fixed;
  bottom: 26px;
  left: 26px;
  width: 56px; height: 56px;
  border-radius: 18px;
  background: var(--accent);
  color: white;
  font-size: 26px;
  border: none;
  box-shadow: 0 8px 24px #7c6cf055;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.fab:hover { background: var(--accent-hover); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-faint);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; }

/* ---------- Stats page ---------- */
.status-banner {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.status-banner .label { font-weight: 700; font-size: 15px; }
.status-banner .sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }

.ring-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.ring-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
}
.ring-card svg { width: 76px; height: 76px; }
.ring-value { font-size: 20px; font-weight: 800; margin-top: 8px; }
.ring-label { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.ring-sub { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.net-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.net-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.net-head .title { font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-dim); }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-left: 5px; }
.net-values { display: flex; gap: 28px; margin-bottom: 10px; }
.net-values .v-label { font-size: 12px; color: var(--text-faint); }
.net-values .v-num { font-size: 18px; font-weight: 700; font-family: 'JetBrains Mono', monospace; direction: ltr; }

.bottom-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.bottom-stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.bottom-stat .num { font-size: 18px; font-weight: 800; font-family: 'JetBrains Mono', monospace; }
.bottom-stat .lbl { font-size: 12px; color: var(--text-faint); margin-top: 3px; }

/* ---------- Terminal ---------- */
.term-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 10px;
}
.term-toolbar .name { font-weight: 700; font-size: 14px; }
.term-status { font-size: 12px; color: var(--text-faint); }
.term-wrap {
  background: #06090f;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px;
  height: 60vh;
  min-height: 380px;
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px 26px;
  width: 100%;
  max-width: 380px;
}
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo .glyph {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(160deg, #241c48, #131a2c);
  border: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-size: 24px;
  margin: 0 auto 12px;
}
.login-title { text-align: center; font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-faint); font-size: 13px; margin-bottom: 22px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  background: #0d1220;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.field input.mono { direction: ltr; text-align: left; }

.error-box {
  background: var(--danger-dim);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.hint-box {
  background: var(--accent-dim);
  color: var(--accent-hover);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
  line-height: 1.7;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: #000000aa;
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 18px 28px;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal-title { font-weight: 800; font-size: 17px; }
.close-btn {
  background: #1a2138; border: none; color: var(--text-dim);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
}

.section-label {
  font-size: 12px; color: var(--text-faint); font-weight: 700;
  margin: 18px 0 8px; letter-spacing: 0.02em;
}
.file-list {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.file-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--card-border);
  font-size: 13.5px;
  cursor: pointer;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: #171f36; }
.file-row .fi { color: var(--accent); width: 18px; text-align: center; }
.file-row .fname { flex: 1; font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: left; }
.file-row .fsize { color: var(--text-faint); font-size: 11.5px; font-family: 'JetBrains Mono', monospace; }

.audit-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--card-border);
  font-size: 12.5px;
}
.audit-row .a-top { display: flex; justify-content: space-between; color: var(--text-dim); }
.audit-row .a-action { font-weight: 700; color: var(--text); }
.audit-row .a-time { color: var(--text-faint); font-family: 'JetBrains Mono', monospace; }

.toast {
  position: fixed; bottom: 20px; right: 20px; left: 20px;
  max-width: 400px; margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13.5px;
  z-index: 100;
  box-shadow: 0 8px 24px #00000055;
}
.toast.error { border-color: #f8717155; color: var(--danger); }
.toast.success { border-color: #34d39955; color: var(--online); }

.loading-spin {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--text-faint); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-loading { display: flex; justify-content: center; padding: 60px 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 8px; }

@media (max-width: 420px) {
  .ring-card svg { width: 64px; height: 64px; }
  .page-title { font-size: 24px; }
}
