/* =========================================================
   08 – Bảng xếp hạng (cá nhân & nhà máy)
   ========================================================= */
.page-bg { position: relative; flex: 1; display: flex; flex-direction: column; }
.page-bg::before {
  content: ''; position: absolute; left: 0; right: 0; top: -1.5rem; height: 49.5rem; z-index: -1; pointer-events: none;
  background: url('../images/bg-game.jpg') right top / 96rem 49.5rem no-repeat;
}
.main { position: relative; z-index: 0; }

.ranking-page { padding: 1.75rem 1.85rem 0 1.9rem; max-width: 78.75rem; }

/* ----- Hero ----- */
.rk-hero { display: flex; justify-content: space-between; gap: 1.6rem; min-height: 5.35rem; }
.rk-hero__eyebrow { margin-top: 1px; font-size: max(0.7rem, var(--fs-min2, 0px)); line-height: 0.95rem; color: var(--orange); text-transform: uppercase; }
.rk-hero__title { margin-top: 0.45rem; font-size: 1.45rem; font-weight: 600; line-height: 1.95rem; color: #172b48; }
.rk-hero__summary { margin-top: 0.25rem; max-width: 25.55rem; font-size: max(0.7rem, var(--fs-min2, 0px)); line-height: 0.95rem; color: var(--muted-2); }
.tiebreak { flex: none; width: 18.45rem; height: 5.35rem; padding: 0.75rem 0.9rem; background: #fff; border: 1px solid #e2e9f2; border-radius: 0.6rem; font-size: max(0.6rem, var(--fs-min, 0px)); line-height: 0.8rem; }
.tiebreak__title { font-weight: 700; color: #2c69d8; }
.tiebreak__list { margin-top: 0.6rem; color: var(--muted-2); }
.rk-divider { width: 72rem; max-width: calc(100% - 3rem); height: 1px; margin: 1.45rem auto 0; background: #e2e9f2; }

/* ----- Thẻ chung ----- */
.rk-card { position: relative; background: #fff; border: 1px solid #e2e9f2; border-radius: 0.65rem; }
.rk-card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.2rem; }
.rk-card__title { font-size: 1rem; font-weight: 600; line-height: 1.3rem; color: #172b48; }
.rk-card__caption { margin-top: 0.15rem; font-size: max(0.6rem, var(--fs-min, 0px)); line-height: 0.8rem; color: var(--muted-2); }

/* ----- Bảng xếp hạng cá nhân ----- */
.personal { margin-top: 1.55rem; padding: 1rem 0 0.5rem; }
.personal .rk-card__head { padding: 0 1.7rem 0 1.05rem; }
.plant-filter { display: flex; gap: 0.2rem; margin-top: 0.15rem; }
.plant-filter button { width: 3.55rem; height: 1.3rem; border-radius: 0.35rem; background: #f6f8fc; font-size: max(0.5rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.75rem; color: var(--muted-2); transition: background-color .2s, color .2s; }
.plant-filter button:first-child { width: 5.4rem; margin-right: 0.3rem; font-size: max(0.55rem, var(--fs-min, 0px)); }
.plant-filter button:hover { background: #eef2f8; }
.plant-filter button.is-active { background: #fff0e8; color: var(--orange); }

.rk-table { margin: 1.25rem 0.5rem 0 0.35rem; }
.rk-row { display: grid; grid-template-columns: 3.25rem 1.75rem 20.65rem 10.95rem 6.15rem 6.35rem 11.75rem 5.45rem 5.85rem; align-items: center; padding-right: 1.95rem; }
.rk-row--head { height: 2.1rem; margin-left: 0.4rem; border-radius: 0.25rem; background: #f6f8fc; font-size: max(0.5rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.65rem; color: var(--muted-2); }
.rk-row--head > span:first-child { padding-left: 0.15rem; }
.rk-row--head > span:last-child { text-align: right; }
.rk-row--head .span2 { grid-column: span 2; padding-left: 1.3rem; }
.rk-body { max-height: 26.55rem; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #dfe7f1 transparent; }
.rk-body .rk-row { position: relative; height: 2.65rem; border-top: 1px solid #e2e9f2; background: #fff; transition: background-color .2s; }
.rk-body .rk-row:first-child { border-top: 0; }
.rk-body .rk-row:hover { background: #f8fafc; }
.rk-row.is-me { background: #e5f7ea; }
.rk-row.is-me:hover { background: #dcf3e3; }
.rk-row.is-me::before { content: ''; position: absolute; left: 0; top: 1px; width: 0.15rem; height: calc(100% - 1px); border-radius: 2px; background: var(--green); }
.rk-rank { justify-self: start; margin-left: 0.6rem; width: 1.35rem; height: 1.35rem; border-radius: 0.7rem; background: #f6f8fc; display: grid; place-items: center; font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.75rem; color: var(--navy); }
.rk-rank--1 { background: #f4bd2e; color: #fff; }
.rk-rank--2 { background: #dce9f3; }
.rk-rank--3 { background: #fff0e8; }
.rk-avatar { position: relative; width: 1.4rem; height: 1.4rem; border-radius: 0.7rem; background: #eaf2fb; display: grid; place-items: center; font-size: max(0.5rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.65rem; color: var(--navy); }
.rk-avatar--gold { background: #fff2d2; border: 1px solid #f4bd2e; }
.rk-avatar img { position: absolute; left: 0.95rem; top: 0; width: 0.45rem; height: 0.45rem; }
.is-me .rk-avatar { background: #f8fafc; }
.rk-emp { position: relative; padding-left: 0; font-size: max(0.7rem, var(--fs-min2, 0px)); }
.rk-emp b { display: block; font-weight: 500; line-height: 0.8rem; color: #172b48; }
.rk-emp span { display: block; margin-top: 1px; line-height: 1.4; color: var(--muted-2); }
.rk-me { position: absolute; left: 7.7rem; top: 50%; transform: translateY(-50%); width: 1.95rem; height: 1.1rem; border-radius: 0.55rem; background: #fff; display: grid; place-items: center; font-size: max(0.55rem, var(--fs-min, 0px)); line-height: 0.75rem; color: #075241; }
.rk-unit b { display: block; font-size: max(0.65rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.85rem; color: #172b48; }
.rk-unit span { display: block; margin-top: 0.15rem; font-size: max(0.7rem, var(--fs-min2, 0px)); line-height: 1.4; color: var(--muted-2); }
.rk-pt { font-size: max(0.7rem, var(--fs-min2, 0px)); font-weight: 500; line-height: 0.75rem; color: #172b48; }
.rk-gemba { justify-self: start; width: 5.35rem; height: 1.2rem; border-radius: 0.35rem; background: #fff0e8; display: grid; place-items: center; font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.75rem; color: var(--orange); white-space: nowrap; }
.rk-time { font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 500; line-height: 0.75rem; color: var(--navy); white-space: pre; }
.rk-time.is-empty { color: var(--muted-2); }
.rk-total { text-align: right; font-size: max(0.6rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.8rem; color: var(--green); }
.rk-empty { padding: 2rem; text-align: center; color: var(--muted-2); font-size: max(0.7rem, var(--fs-min2, 0px)); }
/* .snapshots là CSS grid 2 cột -> 1 item rk-empty duy nhất chỉ chiếm nửa đầu (lệch trái),
   phải chiếm trọn chiều ngang grid thì text-align:center ở trên mới thực sự canh giữa cả khối. */
.snapshots .rk-empty { grid-column: 1 / -1; }

/* ----- Bảng xếp hạng nhà máy ----- */
.factory { margin-top: 1.55rem; padding: 1.05rem 1.15rem 1.15rem; }
.legend { display: flex; gap: 0.4rem; }
.legend span { height: 1.35rem; padding: 0 0.4rem; border-radius: 0.35rem; display: grid; place-items: center; font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.75rem; white-space: nowrap; }
.legend .l-spvb { min-width: 4.6rem; background: rgba(0, 55, 93, .09); color: var(--navy); }
.legend .l-3pl { min-width: 3.9rem; background: rgba(255, 77, 0, .09); color: #ff4d00; }
.legend .l-nt { min-width: 6rem; background: rgba(0, 143, 33, .09); color: var(--green); }
.legend .l-rate { min-width: 7.8rem; background: rgba(44, 105, 216, .09); color: #2c69d8; }
.factory__divider { height: 1px; margin: 0.9rem 0 1rem; background: #e2e9f2; }

.chart { position: relative; height: 20.7rem; border: 1px solid #e2e9f2; border-radius: 0.5rem; overflow: hidden; }
.chart__grid { position: absolute; left: 0; right: 0; height: 1px; }
.chart__grid::before { content: ''; position: absolute; left: 4.25rem; right: 5.45rem; top: 0; height: 1px; background: #e2e9f2; }
.chart__grid i, .chart__grid em { position: absolute; top: -0.35rem; font-size: max(0.6rem, var(--fs-min, 0px)); font-weight: 500; font-style: normal; line-height: 0.65rem; }
.chart__grid i { right: calc(100% - 3.2rem); color: var(--navy); white-space: nowrap; }
.chart__grid em { right: 1.8rem; color: #2c69d8; }
/* justify-content: space-evenly thay vì gap cố định -> tự giãn đều theo đúng số nhà máy hiện
   có (6 nhà máy: BNP/QNP/DOP/LAP/CTP/PNB). gap cố định trước đây tính dư ra ngoài bề rộng
   .chart (overflow:hidden) khi đủ 6 nhóm, khiến nhóm cuối bị cắt gần hết, chỉ lòi ra 1 mẩu cột. */
.chart__groups { position: absolute; left: 5.1rem; right: 5.45rem; top: 0; bottom: 0; display: flex; justify-content: space-evenly; }
.chart__group { position: relative; width: 8.8rem; flex: none; }
/* Mặc định thu về scaleY(0) (chưa chạy animation) -> chỉ "mọc" lên khi .chart có class
   chart--visible (gắn bằng IntersectionObserver trong ranking.js lúc biểu đồ thực sự lọt vào
   viewport). Nếu chạy animation ngay lúc data tải xong như trước, biểu đồ thường đã animate
   xong trước khi người dùng cuộn tới (biểu đồ nằm dưới fold) -> nhìn như không có hiệu ứng gì. */
.chart__bar { position: absolute; bottom: 4.35rem; width: 1.4rem; border-radius: 0.2rem; transform-origin: bottom; transform: scaleY(0); }
.chart.chart--visible .chart__bar { animation: grow .8s ease both; }
.chart__bar b { position: absolute; left: 50%; bottom: calc(100% + 2px); transform: translateX(-50%); font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.75rem; white-space: nowrap; }
.chart__bar--spvb { left: 0.8rem; background: var(--navy); color: var(--navy); }
.chart__bar--3pl { left: 2.6rem; background: #ff4d00; color: #ff4d00; }
.chart__bar--nt { left: 4.4rem; background: var(--green); color: var(--green); }
.chart__bar--rate { left: 6.2rem; background: #2c69d8; color: #2c69d8; }
.chart__label { position: absolute; left: 0; right: 0; bottom: 2.45rem; text-align: center; font-size: max(0.65rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.85rem; color: #172b48; }
.chart__pop { position: absolute; left: 0; right: 0; bottom: 1.5rem; text-align: center; font-size: max(0.5rem, var(--fs-min, 0px)); line-height: 0.65rem; color: var(--muted-2); }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

.factory__subtitle { margin-top: 1.05rem; font-size: 0.95rem; font-weight: 600; line-height: 1.25rem; color: var(--navy); }
.ftable { margin-top: 0.75rem; border: 1px solid #e2e9f2; border-radius: 0.4rem; overflow: hidden; }
.ftable__row { display: grid; grid-template-columns: 4.25rem 8.75rem 10rem 10rem 7rem 9rem 12rem 1fr; align-items: center; padding: 0 0.8rem 0 0.95rem; }
.ftable__row--head { height: 2rem; background: #f6f8fc; font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 700; line-height: 0.75rem; color: var(--muted-2); }
.ftable__body .ftable__row { height: 2.85rem; font-size: max(0.65rem, var(--fs-min, 0px)); line-height: 0.85rem; color: #172b48; }
.ftable__body .ftable__row + .ftable__row { border-top: 1px solid #e2e9f2; }
.ftable__body .ftable__row:hover { background: #fafcfe; }
.c-rank { font-weight: 700; }
.c-plant { font-weight: 600; }
.c-hc { font-size: max(0.6rem, var(--fs-min, 0px)); font-weight: 500; line-height: 0.8rem; color: var(--muted-2); }
.c-spvb { font-weight: 700; color: var(--navy); }
.c-3pl { font-weight: 700; color: #ff4d00; }
.c-nt { font-weight: 700; color: var(--green); }
.c-rate { font-weight: 700; color: #2c69d8; }
.c-badge { width: 9.4rem; height: 1.35rem; border-radius: 0.35rem; display: grid; place-items: center; font-size: max(0.55rem, var(--fs-min, 0px)); font-weight: 600; line-height: 0.75rem; }
.c-badge--lead { background: #fff0e8; color: var(--orange); }
.c-badge--top { background: #e5f7ea; color: var(--green); }
.c-badge--run { background: #f6f8fc; color: var(--muted-2); }

.formula { margin-top: 1.05rem; padding: 0.75rem 0.8rem 0.8rem; background: #eaf2fb; border: 1px solid #e2e9f2; border-radius: 0.45rem; }
.formula h4 { font-size: 0.75rem; font-weight: 600; line-height: 1rem; color: var(--navy); }
.formula ul { margin: 0.45rem 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.45rem; font-size: max(0.65rem, var(--fs-min, 0px)); line-height: 0.85rem; color: #172b48; }

.footer--ranking { padding: 1.1rem 1.85rem 2rem 1.9rem; margin: 0; max-width: 78.75rem; }

/* nowrap + ellipsis: nếu nội dung header vẫn dài hơn cột (vd zoom lạ, viewport hẹp bất thường),
   chữ cắt gọn "..." thay vì tràn đè lên cột bên cạnh như bug đã gặp (cột "THỜI GIAN GAME" quá hẹp
   khiến "BÁO CÁO AN TOÀN/HOẠT ĐỘNG OFFLINE" tràn chữ chồng lên nó). */
.rk-row--head > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rk-me { font-style: normal; }
.page-bg::before, .game-main::before { -webkit-mask-image: linear-gradient(#000 75%, transparent); mask-image: linear-gradient(#000 75%, transparent); }
