/* =====================================================
   CHỐNG TRÀN NGANG TOÀN CỤC
===================================================== */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* =====================================================
   BẢNG ĐIỂM
===================================================== */

.ranking-page {
    max-width: 1400px;
    margin: auto;
    padding: 32px 24px 60px;
}

.ranking-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 22px;
}
.ranking-heading h1 { margin: 6px 0; font-size: 36px; font-weight: 800; }
.ranking-heading p { margin: 0; color: #718096; }

.updated { font-size: 13px; color: #718096; }
.live-dot {
    width: 7px; height: 7px; display: inline-block;
    background: #22c55e; border-radius: 50%; margin-right: 5px;
}

/* CATEGORY */
.category-tabs {
    display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px;
}
.category-mobile-select {
    display: none; position: relative; margin-bottom: 16px;
}
.category-mobile-select label {
    display: block; margin-bottom: 7px; font-size: 11px;
    font-weight: 800; letter-spacing: .05em; color: #64748b;
}
.category-mobile-select select {
    width: 100%; height: 48px;
    appearance: none; -webkit-appearance: none;
    border: 1px solid #dbe2ea; border-radius: 11px;
    background: #fff; color: #0f172a;
    padding: 0 44px 0 14px; font-size: 14px; font-weight: 750;
    outline: none; box-shadow: 0 3px 12px rgba(15,23,42,.04);
}
.category-mobile-select select:focus {
    border-color: #0f766e; box-shadow: 0 0 0 3px rgba(15,118,110,.10);
}
.category-mobile-select::after {
    content: "⌄"; position: absolute; right: 16px; bottom: 13px;
    font-size: 20px; color: #64748b; pointer-events: none;
}
.category-tabs button {
    border: 1px solid #dbe2ea; background: #fff; color: #475569;
    padding: 10px 18px; border-radius: 9px; cursor: pointer;
    font-size: 14px; font-weight: 600; transition: .2s;
}
.category-tabs button:hover { border-color: #0f766e; color: #0f766e; }
.category-tabs button.active {
    background: #0f766e; color: #fff; border-color: #0f766e;
}

/* PODIUM */
.podium {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 12px; margin-bottom: 22px;
}
.podium-player {
    position: relative;
    display: flex; align-items: center; gap: 13px;
    min-height: 88px; padding: 13px 16px;
    background: #fff; border: 1px solid #e4e9ef; border-radius: 12px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, .05);
    min-width: 0;
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow .18s, transform .18s, border-color .18s;
}
.podium-player:hover {
    border-color: #cbd5e1;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .10);
}
.podium-player:active { transform: scale(.985); }
.podium-player.first {
    border-color: #cbd5e1;
    box-shadow: 0 5px 18px rgba(15, 23, 42, .08);
}
.podium-rank {
    font-size: 24px; font-weight: 900; width: 35px; text-align: center;
    flex-shrink: 0;
}
.podium-avatar {
    width: 46px; height: 46px; border-radius: 50%;
    object-fit: cover; background: #e2e8f0; flex-shrink: 0;
}
.podium-info { min-width: 0; flex: 1; overflow: hidden; padding-right: 12px; }
.podium-name {
    font-size: 15px; font-weight: 750;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.podium-points { margin-top: 3px; font-size: 13px; color: #64748b; }
.podium-points strong { color: #0f172a; font-size: 17px; }

.podium-player::after {
    content: "›";
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: #cbd5e1;
    pointer-events: none;
}

/* TOOLBAR */
.toolbar {
    display: flex; justify-content: space-between;
    gap: 15px; align-items: center; margin-bottom: 15px;
}
.searchbox {
    display: flex; align-items: center;
    width: 360px; height: 42px;
    background: #fff; border: 1px solid #dbe2ea;
    border-radius: 9px; overflow: hidden;
}
.searchbox span { padding-left: 13px; color: #64748b; font-size: 20px; }
.searchbox input {
    border: 0; outline: 0; flex: 1; height: 100%;
    padding: 0 12px; font-size: 14px;
}
.filters { display: flex; gap: 7px; }
.filter {
    border: 1px solid #dbe2ea; background: #fff; color: #64748b;
    padding: 9px 14px; border-radius: 8px; cursor: pointer;
}
.filter.active {
    background: #0f172a; color: white; border-color: #0f172a;
}

/* CARD */
.ranking-card {
    background: #fff; border: 1px solid #e2e8f0;
    border-radius: 14px; overflow: hidden;
    box-shadow: 0 5px 20px rgba(15, 23, 42, .05);
}
.ranking-card-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 22px; border-bottom: 1px solid #edf1f5;
}
.ranking-card-head h2 { margin: 3px 0 0; font-size: 21px; }
.table-meta { font-size: 13px; color: #64748b; }

.table-scroll {
    width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
}

table { width: 100%; min-width: 1050px; border-collapse: collapse; }
thead { background: #f8fafc; }
th {
    padding: 13px 14px; text-align: left; font-size: 11px;
    letter-spacing: .04em; color: #64748b; font-weight: 800;
    white-space: nowrap;
}
td {
    padding: 13px 14px; border-top: 1px solid #edf1f5;
    font-size: 14px; color: #334155; white-space: nowrap;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: #f8fafc; }

.stt { width: 60px; text-align: center; color: #64748b; font-weight: 700; }
.player-cell { display: flex; align-items: center; gap: 11px; min-width: 220px; }
.player-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    object-fit: cover; background: #e2e8f0;
}
.player-name { font-weight: 700; color: #0f172a; }
.player-club { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.points { font-size: 17px; font-weight: 850; color: #0f172a; }
.min-points { color: #64748b; font-weight: 600; }
.phone { color: #475569; }
.note { color: #64748b; max-width: 220px; white-space: normal; }

tbody tr.ranking-row { cursor: pointer; }

/* =====================================================
   PLAYER MODAL
===================================================== */

.player-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    animation: fadeIn .18s ease;
    overflow-x: hidden;
    overflow-y: auto;
}
.player-modal.open { display: flex; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0 }
    to   { transform: translateY(0);    opacity: 1 }
}

.player-modal-card {
    position: relative;
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);   /* ưu tiên dvh */
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    overflow-x: hidden;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .28);
    animation: slideUp .22s ease;
    margin: auto;                       /* căn giữa khi viewport thấp */
}

.player-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, .22);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transition: background .15s;
}
.player-modal-close:hover { background: rgba(255, 255, 255, .42); }

.player-modal-head {
    position: relative;
    flex-shrink: 0;
    background: linear-gradient(135deg, #0f766e, #14b8a6);
    padding: 20px 18px 18px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}
.player-modal-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
    background: #e2e8f0;
    border: 3px solid rgba(255, 255, 255, .35);
    flex-shrink: 0;
}
.player-modal-head-info {
    min-width: 0;
    flex: 1;
    overflow: hidden;
}
.player-modal-head-info h3 {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 42px;
}
.player-modal-sub {
    font-size: 12px;
    opacity: .92;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 42px;
}
.player-modal-rank {
    position: absolute;
    right: 14px;
    bottom: 14px;
    background: rgba(255, 255, 255, .22);
    border: 1px solid rgba(255, 255, 255, .28);
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.player-modal-body {
    padding: 16px 18px 18px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.player-modal-points {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
    width: 100%;
}
.player-modal-points > div {
    min-width: 0;
    background: #f0fdfa;
    border: 1px solid #ccfbf1;
    border-radius: 11px;
    padding: 10px 13px;
    overflow: hidden;
}
.player-modal-points .lbl {
    font-size: 10px;
    letter-spacing: .06em;
    text-transform: uppercase;
    font-weight: 800;
    color: #0f766e;
    opacity: .8;
}
.player-modal-points .val {
    margin-top: 2px;
    font-size: 21px;
    font-weight: 850;
    color: #0f766e;
    line-height: 1.1;
    overflow-wrap: anywhere;
}
.player-modal-points .val.min { color: #475569; }

.player-modal-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}
.player-modal-info .info-item {
    min-width: 0;
    background: #f8fafc;
    border: 1px solid #eef2f7;
    border-radius: 10px;
    padding: 9px 12px;
    overflow: hidden;
}
.player-modal-info .info-item.full { grid-column: 1 / -1; }
.player-modal-info .k {
    display: block;
    font-size: 10px;
    letter-spacing: .05em;
    text-transform: uppercase;
    font-weight: 800;
    color: #94a3b8;
    margin-bottom: 3px;
}
.player-modal-info .v {
    display: block;
    font-size: 13.5px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.player-modal-info .v.empty {
    color: #cbd5e1;
    font-weight: 500;
}

/* =====================================================
   TABLET (iPad 768px → 1024px)
===================================================== */
@media (min-width: 601px) and (max-width: 1024px) {
    .ranking-page { padding: 28px 20px 50px; }
    .ranking-heading h1 { font-size: 32px; }

    .podium {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }
    .podium-player.first,
    .podium-player:nth-child(1) {
        grid-column: 1 / -1;
        justify-self: center;
        width: 100%;
        max-width: 560px;
    }
    .podium-player {
        min-height: 78px;
        padding: 12px 30px 12px 14px;
        gap: 11px;
        border-radius: 12px;
    }
    .podium-rank { width: 30px; font-size: 22px; }
    .podium-avatar { width: 44px; height: 44px; }
    .podium-name { font-size: 14px; }
    .podium-points { font-size: 12px; margin-top: 3px; }
    .podium-points strong { font-size: 16px; }

    .ranking-card .player-avatar {
        width: 44px !important;
        height: 44px !important;
    }
    .ranking-card .player-name { font-size: 15.5px !important; }
    .ranking-card .player-club { font-size: 12px !important; }
    .ranking-card .points { font-size: 20px !important; }
    .ranking-card tbody tr.ranking-row {
        padding: 14px 36px 14px 18px !important;
    }
    .ranking-card tbody tr.ranking-row::after {
        font-size: 22px !important;
        right: 14px !important;
    }
}

/* =====================================================
   MOBILE / TABLET (≤ 1024px)
===================================================== */
@media (max-width: 1024px) {

    .category-tabs { display: none; }
    .category-mobile-select { display: block; }

    .toolbar { display: block; }
    .searchbox { width: 100%; margin-bottom: 9px; }
    .filters { overflow-x: auto; }
    .filter { flex-shrink: 0; }

    .ranking-card-head { padding: 16px; }
    .ranking-card-head h2 { font-size: 18px; }

    /* =====================================================
       BẢNG → GRID LIST
    ===================================================== */

    .ranking-card .table-scroll {
        overflow: visible !important;
    }

    .ranking-card table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: collapse !important;
    }

    .ranking-card thead {
        display: none !important;
    }

    .ranking-card tbody {
        display: block !important;
        width: 100% !important;
    }

    .ranking-card tbody tr.ranking-row {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) auto !important;
        gap: 12px !important;
        align-items: center !important;
        padding: 12px 32px 12px 14px !important;
        border-bottom: 1px solid #edf1f5 !important;
        background: #fff !important;
        position: relative !important;
    }

    .ranking-card tbody tr.ranking-row:hover {
        background: #f8fafc !important;
    }

    .ranking-card tbody td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        white-space: normal !important;
        overflow: visible !important;
        background: transparent !important;
        color: #334155 !important;
        font-size: 14px !important;
        width: auto !important;
    }

    .ranking-card td.col-stt,
    .ranking-card td.col-min,
    .ranking-card td.col-phone,
    .ranking-card td.col-court,
    .ranking-card td.col-company,
    .ranking-card td.col-note {
        display: none !important;
    }

    .ranking-card td.col-name {
        display: block !important;
        min-width: 0 !important;
    }

    .ranking-card td.col-points {
        display: block !important;
        text-align: right !important;
        white-space: nowrap !important;
    }

    .ranking-card .player-cell {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        min-width: 0 !important;
        width: 100% !important;
    }

    .ranking-card .player-avatar {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0 !important;
        border-radius: 50% !important;
        object-fit: cover !important;
    }

    .ranking-card .player-cell > div {
        min-width: 0 !important;
        flex: 1 1 auto !important;
        overflow: hidden !important;
        display: block !important;
    }

    .ranking-card .player-name {
        display: block !important;
        font-size: 14.5px !important;
        font-weight: 700 !important;
        color: #0f172a !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        line-height: 1.3 !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: auto !important;
        height: auto !important;
    }

    .ranking-card .player-club {
        display: block !important;
        font-size: 11.5px !important;
        color: #94a3b8 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        line-height: 1.3 !important;
        margin-top: 2px !important;
    }

    .ranking-card .points {
        display: inline-block !important;
        font-size: 19px !important;
        font-weight: 850 !important;
        color: #0f766e !important;
        line-height: 1 !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .ranking-card tbody tr.ranking-row::after {
        content: "›" !important;
        position: absolute !important;
        right: 10px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        font-size: 20px !important;
        color: #cbd5e1 !important;
        pointer-events: none !important;
    }

    /* =====================================================
       MODAL — NẰM GIỮA MÀN HÌNH, KHÔNG BỊ THANH ĐỊA CHỈ CHE
    ===================================================== */
    .player-modal {
        align-items: center;
        justify-content: center;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        overflow-x: hidden;
        overflow-y: auto;
    }
    .player-modal-card {
        max-width: 100%;
        width: 100%;
        max-height: calc(100vh - 32px);
        max-height: calc(100dvh - 32px);
        border-radius: 18px;
        overflow-x: hidden;
        margin: auto;
    }
    /* Bỏ thanh kéo ở đỉnh vì modal không còn là bottom sheet */
    .player-modal-card::before { display: none; }

    .player-modal-head {
        padding: 18px 16px 16px;
        border-radius: 18px 18px 0 0;
        min-width: 0;
    }
    .player-modal-avatar { width: 48px; height: 48px; }
    .player-modal-head-info { min-width: 0; }
    .player-modal-head-info h3 { font-size: 16.5px; }
    .player-modal-sub { font-size: 11.5px; }
    .player-modal-body {
        padding: 13px 14px 16px;
        overflow-x: hidden;
    }
    .player-modal-points { gap: 8px; margin-bottom: 10px; }
    .player-modal-points > div {
        padding: 9px 11px;
        border-radius: 10px;
        min-width: 0;
    }
    .player-modal-points .val { font-size: 19px; }
    .player-modal-info { gap: 7px; }
    .player-modal-info .info-item {
        padding: 8px 10px;
        border-radius: 9px;
        min-width: 0;
    }
    .player-modal-info .v { font-size: 12.5px; }
}

/* =====================================================
   ĐIỆN THOẠI NHỎ (≤ 600px)
===================================================== */
@media (max-width: 600px) {
    .ranking-page { padding: 22px 12px 40px; }
    .ranking-heading { display: block; }
    .ranking-heading h1 { font-size: 28px; }
    .updated { margin-top: 10px; }

    .podium { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 18px; }
    .podium-player.first,
    .podium-player:nth-child(1) {
        grid-column: 1 / -1;
        justify-self: center;
        width: 100%;
        max-width: 400px;
    }
    .podium-player {
        min-height: 66px;
        padding: 10px 26px 10px 12px;
        gap: 9px;
        border-radius: 11px;
    }
    .podium-rank { width: 24px; font-size: 19px; }
    .podium-avatar {
        width: 38px; height: 38px;
        border: 2px solid #fff;
        box-shadow: 0 0 0 1px #e2e8f0;
    }
    .podium-info { min-width: 0; padding-right: 0; }
    .podium-name { font-size: 12.5px; font-weight: 750; line-height: 1.25; }
    .podium-points { margin-top: 2px; font-size: 11px; }
    .podium-points strong { font-size: 14.5px; font-weight: 850; }
    .podium-player::after { font-size: 16px; right: 8px; }

    /* Modal trên điện thoại: vẫn căn giữa, thêm padding 2 bên */
    .player-modal {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
    .player-modal-card {
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        border-radius: 16px;
    }
    .player-modal-head { border-radius: 16px 16px 0 0; }
}