FoundryManager — mini Azure AI Foundry portal (local web UI)
=============================================================

MUC DICH: dang nhap 1 tai khoan Azure Foundry -> xem quota TAT CA model theo region
-> tick chon (loc theo ten, tick-all) -> tao resource+project (chon region)
-> deploy hang loat 1 phat -> xuat deploy-name + endpoint + API key tung model.

KIEN TRUC: ARM REST thuan (KHONG camoufox/browser-automation).
  - Dang nhap = device-code (thu cong, xu ly duoc password + mail-code + MFA + federated).
  - Luu refresh-token vao profiles/<ten>/token.json -> lan sau tu refresh, khoi login lai.
  - Proxy per-profile: profiles/<ten>/proxy.txt (http/socks5://user:pass@ip:port). Ap cho ca token + ARM.

CHAY TREN WINDOWS VPS (KHUYEN NGHI):
  Chi can copy FOUNDRY_STUDIO_INSTALL.bat va double-click bang user Windows binh thuong.
  BAT tu tai release public tu Hugging Face primary/mirror, verify SHA256, tao venv,
  cai thu vien con thieu va mo http://127.0.0.1:8799 trong tab moi.
  KHONG can Run as administrator. Neu UAC dung Windows account khac thi profile/browser/Azure CLI
  cua user thuong se khong duoc dung chung.

  Profile duoc giu rieng tai:
  %LOCALAPPDATA%\FoundryManagerStudio\data\profiles

CHAY THU CONG CHO DEV:
  python -m pip install -r requirements.lock
  python app.py

CHAY TREN VPS (truy cap tu xa):
  - An toan nhat: SSH tunnel:  ssh -L 8799:127.0.0.1:8799 user@vps  roi mo localhost:8799 tren may minh.
  - Hoac dat FM_HOST=0.0.0.0 (mo cong) — NHUNG phai co tuong lua/whitelist IP, vi tool quan ly acc Azure.

SKU:
  - Mac dinh chi SERVERLESS: GlobalStandard -> DataZoneStandard -> Standard (tra theo token, tao khong mat tien).
  - Tick "Cho phep PTU" de hien them SKU PTU (ProvisionedManaged...) — LUU Y PTU tinh tien luc provision.
  - Tool KHONG BAO GIO tao managed-compute GPU (H100/A100) — chi la deployment token Cognitive Services.

AN TOAN / KHONG VI PHAM:
  - Device-code = dang nhap tuong tac binh thuong -> rui ro co thap hon nhap-pass-tu-dong.
  - Dung 1 IP on dinh cho moi acc (dung xoay proxy cho acc chinh -> tranh 'impossible travel').
  - Tao deployment serverless la thao tac hop le (giong portal). Tranh PTU/GPU neu khong can.
  - Chi dung cho tenant ban so huu.

FILES:
  arm.py       - auth device-code + refresh + proxy + ARM request/poll
  foundry.py   - subs/tenant, catalog, quota matrix, planner, create infra, deploy, keys, test
  app.py       - Flask backend
  static/index.html - Web UI
  profiles/    - token + proxy tung account (KHONG commit len repo public)

COST:
  - Actual da ghi nhan = Azure Cost Management da hach toan (thuong tre 8-24 gio).
  - Uoc tinh chua ghi nhan = Azure Monitor usage x effective/list rate.
  - Tam tinh hien tai = Actual cac ngay da chot + phan moi, khong cong trung.
  - Chi phi VM/Storage/Search khac trong subscription khong bi cong vao Foundry.

XUAT: CSV / JSON (nut trong buoc 5). Cot: deploy_name, model, version, sku, capacity, endpoint, key.
