/* ===================================================
   VCTIERS - mobile.css  |  v2 - Full mobile fix
   =================================================== */

/* ─────────────────────────────────────────────────────
   FIX 0: .pm2-content không có CSS layout — JS set display:flex
   nhưng không có width/height → skin hiện, info biến mất
   ───────────────────────────────────────────────────── */
.pm2-content {
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    /* display được JS kiểm soát (none / flex) */
}

/* ─────────────────────────────────────────────────────
   FIX 1: mobile-search-btn ẩn mặc định, chỉ show ≤600px
   ───────────────────────────────────────────────────── */
.mobile-search-btn { display: none; }

/* ─────────────────────────────────────────────────────
   NAVBAR — tablet (≤900px)
   ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .nav-links  { display: none; }
    .hamburger  { display: flex; }
    .search-bar { min-width: 130px; padding: 6px 10px; }
    .search-kbd { display: none; }
}

/* NAVBAR — mobile (≤600px) */
@media (max-width: 600px) {
    .search-bar        { display: none; }
    .mobile-search-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--input-bg);
        border: 1.5px solid var(--border);
        border-radius: 8px;
        width: 38px; height: 38px;
        cursor: pointer;
        color: var(--muted-fg);
        transition: border-color .15s, color .15s;
        flex-shrink: 0;
    }
    .mobile-search-btn:active { border-color: #4a6cf7; color: var(--fg); }
    .nav-right         { min-width: auto; gap: 4px; }
    .logo-text         { font-size: 18px; }
    .navbar            { padding: 0 12px; }
    .navbar-wrapper    { padding: 8px 10px 0; }
}

/* Mobile menu */
.mobile-menu {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

/* ─────────────────────────────────────────────────────
   FIX 2: Search overlay — bottom sheet trên mobile
   ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .search-overlay {
        padding-top: 0 !important;
        align-items: flex-end;
    }
    .search-modal {
        border-radius: 16px 16px 0 0;
        max-width: 100%; width: 100%;
        border-left: none; border-right: none; border-bottom: none;
    }
    .search-modal-header { padding: 20px 16px 16px; }
    .search-results      { max-height: 55vh; }
}

/* ─────────────────────────────────────────────────────
   FIX 3: Main layout padding — navbar là static rồi
   ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    main { padding: 16px 10px 0 !important; }
}

/* ─────────────────────────────────────────────────────
   TABS
   ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .tabs-container { gap: 2px; padding-bottom: 2px; }
    .tab            { min-width: 68px; padding: 6px 8px 8px; font-size: 11px; gap: 3px; }
    .tab-icon       { width: 22px; height: 22px; }
}

/* Content card */
@media (max-width: 600px) {
    .content-card { padding: 12px 8px 24px; border-radius: 0 8px 8px 8px; }
}

/* ─────────────────────────────────────────────────────
   FIX 4: Info bar — server IP không bị tràn ra ngoài
   ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .info-bar    { flex-wrap: wrap; gap: 8px; justify-content: flex-start; margin-bottom: 14px; }
    .server-info { order: -1; width: 100%; }
}
@media (max-width: 480px) {
    .info-bar        { flex-direction: column; align-items: flex-start; }
    .info-btn        { font-size: 13px; padding: 7px 12px; }
    .server-ip-chip  { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
    .server-ip-row   { flex-wrap: wrap; }
}

/* ─────────────────────────────────────────────────────
   Overall ranking — table header + player rows
   ───────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .th-tiers     { display: none; }
    .th-region    { width: 72px; }
    .th-player    { padding-left: 54px; }
    .player-tiers { display: none; }
    /* FIX: player-row không tràn ngang khi player-tiers bị ẩn */
    .player-row   { overflow: hidden; max-width: 100%; }
    .player-list  { overflow: hidden; }
}
@media (max-width: 600px) {
    .table-header { padding: 0 6px; font-size: 11px; gap: 8px; }
    .th-num       { width: 36px; }
    .th-region    { width: 60px; }
    .player-row   { padding: 5px 8px 5px 5px; gap: 8px; border-radius: 8px; }
    .player-name  { font-size: 15px; }
    .player-title { font-size: 12px; }
    .player-region { padding: 4px 8px; font-size: 12px; min-width: 44px; }
}
@media (max-width: 420px) {
    .rank-badge-wrap   { width: 52px; height: 48px; }
    .player-bust-wrap  { width: 46px; height: 54px; }
    .player-bust       { width: 46px; }
    .rank-number       { font-size: 17px; padding-left: 7px; }
    .player-name       { font-size: 13px; }
    .player-title      { display: none; }
    /* Giữ region — thông tin quan trọng */
    .player-region     { min-width: 40px; font-size: 11px; padding: 3px 6px; }
}

/* ─────────────────────────────────────────────────────
   FIX 5: TIER GRID MỚI (.tier-grid-new / .tcn-*)
   class này dùng trong mode.php nhưng trước đây KHÔNG được fix
   ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .tier-grid-new {
        gap: 8px;
        padding-bottom: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .tier-col-new       { flex: 0 0 185px; min-width: 185px; }
    .tcn-header         { padding: 12px 14px; gap: 8px; }
    .tcn-cup            { width: 28px; height: 28px; }
    .tcn-tier-label     { font-size: 17px; }
    .tcn-avatar         { width: 48px; height: 54px; }
    .tcn-player-card    { padding: 8px 10px; gap: 8px; }
    .tcn-name           { font-size: 13px; }
}
@media (max-width: 480px) {
    .tier-col-new       { flex: 0 0 155px; min-width: 155px; }
    .tcn-header         { padding: 10px 10px; gap: 6px; border-radius: 10px; }
    .tcn-cup            { width: 24px; height: 24px; }
    .tcn-tier-label     { font-size: 15px; }
    .tcn-player-count   { font-size: 10px; }
    .tcn-avatar         { width: 40px; height: 46px; }
    .tcn-player-card    { padding: 7px 8px; gap: 7px; border-radius: 8px; }
    .tcn-name           { font-size: 12px; }
    .tcn-badge          { font-size: 9px; padding: 2px 5px; }
    .tcn-trophy-sm      { width: 16px; height: 16px; }
}
@media (max-width: 360px) {
    /* Màn hình rất nhỏ — col hẹp hơn nữa */
    .tier-col-new   { flex: 0 0 138px; min-width: 138px; }
    .tcn-avatar     { width: 34px; height: 40px; }
    .tcn-name       { font-size: 11px; }
}

/* ─────────────────────────────────────────────────────
   Tier grid CŨ (.tier-grid / .tier-col) — giữ lại phòng khi dùng
   ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .tier-grid              { -webkit-overflow-scrolling: touch; }
    .tier-col               { flex: 0 0 180px; min-width: 180px; }
    .tier-col-header        { font-size: 15px; padding: 10px 8px; gap: 6px; }
    .tier-col-header img    { width: 18px; height: 18px; }
}
@media (max-width: 480px) {
    .tier-col               { flex: 0 0 155px; min-width: 155px; }
    .tier-player-row        { padding: 8px 10px; gap: 8px; }
    .tier-player-name       { font-size: 13px; }
    .tier-player-avatar     { width: 24px; height: 24px; }
    .tier-col-header        { font-size: 14px; padding: 8px; }
}

/* ─────────────────────────────────────────────────────
   FIX 6: Player modal — bottom sheet + iOS scroll fix
   ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
    /* Tất cả modal-overlay xuất hiện từ dưới lên */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    /* Player modal v2 */
    .player-modal-v2 {
        flex-direction: column;
        max-height: 92vh;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        border-left: none; border-right: none; border-bottom: none;
        overflow: hidden;
    }

    /* pm2-content: trên mobile là column (skin trên, info dưới) */
    .pm2-content {
        flex-direction: column !important;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Thu nhỏ skin trên mobile */
    .pm2-left {
        width: 100%; min-width: 0;
        height: 110px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .pm2-skin {
        width: 70px;
        height: 100%;
        object-fit: contain;
        object-position: center center;
        margin: 0 auto;
        display: block;
    }
    /* FIX: pm2-right phải scroll được trên iOS */
    .pm2-right {
        flex: 1;
        padding: 14px 16px 28px;
        gap: 10px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
    }
    .pm2-name      { font-size: 19px; }
    .pm2-stat-val  { font-size: 19px; }
    .pm2-close     { top: 10px; right: 12px; width: 36px; height: 36px; }

    /* Info modal */
    .modal-box {
        padding: 20px 16px !important;
        border-radius: 16px 16px 0 0;
        border-left: none; border-right: none; border-bottom: none;
        max-width: 100% !important;
        width: 100%; margin: 0;
        max-height: 85vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .info-modal-box { max-width: 100% !important; }
}

/* ─────────────────────────────────────────────────────
   TIER SLIDE PANEL — Overall page, mobile only
   Nút "›" → panel phủ toàn bộ hàng, scroll ngang thoải mái
   ───────────────────────────────────────────────────── */

/* Wrapper — không overflow:hidden để panel không bị clip */
.player-row-wrap {
    position: relative;
    border-radius: 10px;
}

/* Nút mũi tên + panel: ẩn trên desktop */
.tier-peek-btn  { display: none; }
.tier-slide-panel { display: none; }

@media (max-width: 900px) {
    /* Nút peek */
    .tier-peek-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 28px; height: 28px;
        border-radius: 6px;
        background: var(--secondary);
        border: 1px solid var(--border);
        color: var(--muted-fg);
        cursor: pointer;
        margin-left: 4px;
        padding: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .tier-peek-btn:active { background: var(--accent); color: var(--fg); }

    /* Panel phủ toàn bộ hàng từ trái sang phải */
    .tier-slide-panel {
        display: flex;
        align-items: center;
        gap: 0;
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        /* Bắt đầu ẩn xuống dưới (scale + opacity) */
        opacity: 0;
        pointer-events: none;
        transform: translateX(12px);
        transition: opacity 0.18s ease, transform 0.18s ease;
        background: var(--card);
        border: 2px solid var(--border);
        border-radius: 10px;
        z-index: 5;
        overflow: hidden;
    }
    .tier-slide-panel.open {
        opacity: 1;
        pointer-events: auto;
        transform: translateX(0);
    }

    /* Vùng scroll ngang chứa tất cả chips */
    .tier-slide-inner {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        padding: 0 8px;
        /* Không wrap — scroll ngang để xem hết */
        flex-wrap: nowrap;
        height: 100%;
    }
    .tier-slide-inner::-webkit-scrollbar { display: none; }

    /* Chip tier */
    .tier-slide-chip {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        flex-shrink: 0;
        min-width: 38px;
    }
    .tier-slide-chip img {
        width: 22px; height: 22px;
        object-fit: contain;
        mix-blend-mode: screen;
    }
    .tier-slide-chip span {
        font-size: 8px;
        font-weight: 800;
        padding: 1px 4px;
        border-radius: 3px;
        white-space: nowrap;
        letter-spacing: 0.2px;
    }
    /* Badge colors */
    .tier-slide-chip.badge-ht1 span { background: rgba(192,57,43,.3);  color: #ff8c42; }
    .tier-slide-chip.badge-ht2 span { background: rgba(230,126,34,.3); color: #f7c45e; }
    .tier-slide-chip.badge-ht3 span { background: rgba(240,192,0,.3);  color: #ffe66d; }
    .tier-slide-chip.badge-ht4 span { background: rgba(39,174,96,.2);  color: #80ff8c; }
    .tier-slide-chip.badge-ht5 span { background: rgba(22,160,133,.2); color: #45d9b0; }
    .tier-slide-chip.badge-lt1 span { background: rgba(192,57,43,.3);  color: #ff8c42; }
    .tier-slide-chip.badge-lt2 span { background: rgba(230,126,34,.3); color: #f7c45e; }
    .tier-slide-chip.badge-lt3 span { background: rgba(41,128,185,.3); color: #74b9ff; }
    .tier-slide-chip.badge-lt4 span { background: rgba(108,92,231,.3); color: #a29bfe; }
    .tier-slide-chip.badge-lt5 span { background: rgba(74,81,104,.2);  color: #8896b0; }

    /* Nút đóng — dính sát phải, không scroll theo */
    .tier-slide-close {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 36px; height: 100%;
        border-left: 1px solid var(--border);
        background: var(--secondary);
        color: var(--muted-fg);
        cursor: pointer;
        padding: 0;
        border-radius: 0 8px 8px 0;
        -webkit-tap-highlight-color: transparent;
    }
    .tier-slide-close:active { background: var(--accent); color: var(--fg); }
}

/* ─────────────────────────────────────────────────────
   FIX 7: body overflow:hidden trên iOS Safari
   Dùng position:fixed thay vì overflow:hidden để tránh jump
   (override bằng JS class — xem main.js)
   ───────────────────────────────────────────────────── */
body.modal-open {
    position: fixed;
    width: 100%;
    overflow-y: scroll; /* giữ scrollbar để tránh layout shift */
}

/* ─────────────────────────────────────────────────────
   FIX 8: Player profile page (player.php) — inline style
   padding-top:100px hardcode khi navbar đã static
   ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Override inline style của player.php */
    main[style*="padding-top:100px"],
    main[style*="padding-top: 100px"] {
        padding-top: 16px !important;
    }
    .profile-card          { padding: 18px 14px; }
    .profile-username      { font-size: 22px; }
    .profile-tier-grid     { gap: 8px; }
    .profile-tier-item     { min-width: 80px; padding: 12px 14px; }
    .profile-tier-icon img { width: 26px; height: 26px; }
}
@media (max-width: 480px) {
    .profile-header        { gap: 14px; }
    .profile-avatar-wrap   { width: 72px; height: 72px; }
    .profile-username      { font-size: 20px; }
    .profile-meta          { font-size: 13px; gap: 6px; }
    .profile-tier-item     { min-width: 72px; padding: 10px 10px; }
    .section-title         { font-size: 14px; }
}

/* ─────────────────────────────────────────────────────
   Footer & Toast
   ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .site-footer { padding: 32px 16px; font-size: 14px; margin-top: 48px; }
    .toast       { bottom: 16px; left: 16px; right: 16px; transform: none; text-align: center; }
}

/* ─────────────────────────────────────────────────────
   Touch UX improvements
   ───────────────────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .player-row, .tier-player-row, .tcn-player-card,
    .dropdown-item, .mobile-item, .info-btn, .copy-btn, .tab {
        -webkit-tap-highlight-color: transparent;
    }

    /* Active states thay hover */
    .player-row:active    { background: var(--accent); }
    .tier-player-row:active { background: var(--accent); }
    .tcn-player-card:active { background: var(--accent); border-color: rgba(255,255,255,.12); }
    .tab:active           { background: var(--accent); color: var(--fg); }

    /* Scroll mượt */
    .tabs-container, .tier-grid, .tier-grid-new,
    .search-results, .pm2-right {
        -webkit-overflow-scrolling: touch;
    }
}

/* ─────────────────────────────────────────────────────
   Landscape phone
   ───────────────────────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) {
    .player-modal-v2 { flex-direction: row; max-height: 88vh; }
    .pm2-content     { flex-direction: row !important; }
    .pm2-left        { width: 120px; min-width: 120px; height: auto; flex-shrink: 0; }
    .pm2-right       { max-height: 88vh; flex: 1; }
    .tier-grid-new   { max-height: 70vh; }
}
